Load data

library(easypackages)
libraries("here","pheatmap","reshape2","ggplot2","patchwork","Biobase","readxl")
source(here("code","genelistOverlap.R"))
options(stringsAsFactors = FALSE)

plspath = here("pls")
datapath = here("data","tidy")
plotdir = here("plots")

ndigits2use = 4
fdr_thresh = 0.05
fontSize = 20
dotSize = 10

mod_names = c("M1","M2","M3","M4","M5","M6","M7","M8","M9","M10",
              "M11","M12","M13","M14","M15","M16","M17","M18","M19","M20","M21")
nmods = length(mod_names)

# Load in gene lists for enrichment analyses
load(here("data","tidy","enrichment_data2.Rdata"))
load(here("data","tidy","gandal_genelists.Rdata"))
load(here("data","tidy","velmeshev_genelists.Rdata"))
load(here("data","tidy","won_genelists.Rdata"))

# wgcna_res = read.csv(here("WGCNAresults","wgcna_results_summary.csv"))
wgcna_res = read_excel(here("WGCNAresults","wgcna_results_summary.xlsx"))
backgroundTotal = dim(wgcna_res)[1]
bglist = wgcna_res$geneSymbol
M0_size = dim(subset(wgcna_res, wgcna_res$moduleLabels==0))[1]


pls_fname = "plsres_all_sa_GenTemp_sexAdj_MEcorr_bootCI4plotting_LV1_ci95.csv"
fname = here("pls","results",pls_fname)
plsbootdata = read.csv(fname)

var2use = "nonzero"

td_tmp = subset(plsbootdata, plsbootdata$Grp=="TD")
rownames(td_tmp) = 1:nmods
poor_tmp = subset(plsbootdata, plsbootdata$Grp=="Poor")
rownames(poor_tmp) = 1:nmods
good_tmp = subset(plsbootdata, plsbootdata$Grp=="Good")
rownames(good_tmp) = 1:nmods

td_mods = as.numeric(rownames(td_tmp)[td_tmp[,var2use]==1])
asd_poor_mods = as.numeric(rownames(poor_tmp)[poor_tmp[,var2use]==1])
asd_good_mods = as.numeric(rownames(good_tmp)[good_tmp[,var2use]==1])

if (identical(td_mods,numeric(0))){
  td_mods = NA
} else if (identical(asd_poor_mods,numeric(0))){
  asd_poor_mods = NA
} else if (identical(asd_good_mods,numeric(0))){
  asd_good_mods = NA
}

mask = logical(length = nmods)
nonzero_mods = sort(unique(c(td_mods, asd_poor_mods, asd_good_mods)))
mask[nonzero_mods] = TRUE
zero_mods = 1:nrow(td_tmp)
zero_mods = zero_mods[!mask]

nz_mods = mod_names[nonzero_mods]
z_mods = mod_names[zero_mods]

# non-zero and zero modules
nonzeromods = nonzero_mods
zeromods = zero_mods

# Grab non-zero modules and report percentage of genes falling within those modules
mask = is.element(wgcna_res$moduleLabels, nonzeromods)
nonzeromod_data = subset(wgcna_res, mask)
nz_genes = nonzeromod_data$geneSymbol
write(nz_genes, file = file.path(datapath,"nonzeromod_genes_SA_LV1.txt"))
# percentage of clustered genes falling within those modules
nz_prop = dim(nonzeromod_data)[1]/(backgroundTotal-M0_size)
nz_mods
##  [1] "M1"  "M2"  "M4"  "M6"  "M7"  "M10" "M11" "M13" "M14" "M16" "M18" "M20"
## [13] "M21"
nz_prop
## [1] 0.6890954
# Grab zero modules and report percentage of genes falling within those modules
mask = is.element(wgcna_res$moduleLabels, zeromods)
zeromod_data = subset(wgcna_res, mask)
z_genes = zeromod_data$geneSymbol
write(z_genes, file = file.path(datapath,"zeromod_genes_SA_LV1.txt"))
# percentage of clustered genes falling within those modules
z_prop = dim(zeromod_data)[1]/(backgroundTotal-M0_size)
z_mods
## [1] "M3"  "M5"  "M8"  "M9"  "M12" "M15" "M17" "M19"
z_prop
## [1] 0.3109046

Annotate each module by enrichment in broadly expressed and brain-specific genes

geneclasses = c("BroadGenesVG","BrainGenesVG")
outcols = c("OR","pval","fdr")

out_mats = vector(mode = "list", length = length(geneclasses))
names(out_mats) = geneclasses
for (igc in 1:length(geneclasses)){
  out_res = data.frame(matrix(nrow = length(mod_names), 
                              ncol = length(outcols)))
  colnames(out_res) = outcols
  rownames(out_res) = mod_names

  # intersect genes2 list with background 
  genes2 = eval(as.name(geneclasses[igc]))
  mask = is.element(genes2,bglist)
  genes2 = data.frame(genes2[mask])

  for (imod in 1:length(mod_names)){
    # filename for module list
    genes1 = wgcna_res$geneSymbol[wgcna_res$moduleLabels==imod]
    
    overlap_res = genelistOverlap(genes1,
                                  genes2,
                                  backgroundTotal, 
                                  print_result = FALSE, 
                                  header = FALSE)
    out_res[imod,1] = overlap_res[[1]]$OR
    out_res[imod,2] = overlap_res[[1]]$hypergeo_p
  }
  out_res[,3] = p.adjust(out_res[,2], method = "fdr")
  out_mats[[igc]] = out_res
}

Modules enriched for broadly expressed genes

out_mats[[1]]
##            OR         pval          fdr
## M1  1.5815849 1.139045e-06 2.657771e-06
## M2  1.5316153 2.147771e-05 4.510318e-05
## M3  0.5449710 1.000000e+00 1.000000e+00
## M4  2.8610973 1.554145e-22 3.263705e-21
## M5  2.1718314 1.794960e-12 9.423540e-12
## M6  0.5160052 1.000000e+00 1.000000e+00
## M7  2.7396874 8.906490e-18 9.351815e-17
## M8  0.5593113 9.999997e-01 1.000000e+00
## M9  1.2091895 1.110790e-01 1.794352e-01
## M10 2.2929897 7.748199e-11 2.711870e-10
## M11 2.3033904 3.167846e-10 8.315596e-10
## M12 1.0797659 3.838475e-01 5.373865e-01
## M13 2.4163735 3.093854e-10 8.315596e-10
## M14 3.2033004 3.938713e-16 2.757099e-15
## M15 1.5250302 2.786712e-03 4.876746e-03
## M16 0.6472224 9.993014e-01 1.000000e+00
## M17 0.3147719 1.000000e+00 1.000000e+00
## M18 1.1586500 2.247784e-01 3.371676e-01
## M19 0.4462797 9.999993e-01 1.000000e+00
## M20 1.7165930 2.370689e-03 4.525861e-03
## M21 3.9378006 3.461351e-12 1.453767e-11

Modules enriched for brain-specific genes

out_mats[[2]]
##            OR         pval         fdr
## M1  1.0068056 0.9748154711 0.999999804
## M2  1.1037777 0.3469296899 0.809502610
## M3  0.5915155 0.9999514091 0.999999804
## M4  1.5312506 0.0013649801 0.009554861
## M5  0.4254177 0.9999998042 0.999999804
## M6  0.9319914 0.7536839133 0.999999804
## M7  1.0277114 0.5250696261 0.999999804
## M8  1.6365722 0.0010703287 0.009554861
## M9  0.5636704 0.9991416678 0.999999804
## M10 0.9999960 0.5790889017 0.999999804
## M11 1.6044309 0.0030089066 0.015796760
## M12 0.3882616 0.9999939700 0.999999804
## M13 1.1628150 0.2557501163 0.671344055
## M14 0.6494483 0.9873310885 0.999999804
## M15 0.7366967 0.9475324842 0.999999804
## M16 1.5517788 0.0115805606 0.048638355
## M17 1.9033626 0.0003005418 0.006311379
## M18 1.2898588 0.1296696166 0.389008850
## M19 1.5310519 0.0267260997 0.093541349
## M20 1.0151161 0.5309440575 0.999999804
## M21 0.5123359 0.9910803412 0.999999804

Plot correlation values across groups

Surface Area LV1

sa_data = read.csv(file.path(plspath,"results","plsres_all_sa_GenTemp_sexAdj_MEcorr_bootCI4plotting_LV1_ci95.csv"))
sa_good = subset(sa_data,sa_data$Grp=="Good")
sa_poor = subset(sa_data,sa_data$Grp=="Poor")
sa_td = subset(sa_data,sa_data$Grp=="TD")


#------------------------------------------------------------------------------
fontSize = 18
data4heatmap = sa_data
level_ordering = rev(c("M13","M2","M16","M21","M4","M10","M6","M7","M11","M15",
                   "M20","M3","M17","M5","M19","M14","M12","M9","M8","M18","M1"))
data4heatmap$ModName = factor(data4heatmap$ModName, 
                              levels = level_ordering)
data4heatmap$Grp = factor(data4heatmap$Grp, levels = c("Poor","Good","TD")) 
me_corr_comp = data.frame(matrix(nrow = dim(data4heatmap)[1], ncol = 3))
colnames(me_corr_comp) = c("Grp","gclust","allVertices")
me_corr_comp$Grp = data4heatmap$Grp
me_corr_comp$gclust = data4heatmap$corr
p = ggplot(data = data4heatmap) + 
  geom_tile(aes(y = ModName, x = Grp, fill= corr)) + 
  geom_text(aes(y= ModName, x=Grp, label = round(corr,2)),size = 5) + 
  scale_fill_gradientn(colors = colorRampPalette(c("blue","white","red"))(100), limits=c(-0.8,0.8)) +
  # scale_fill_gradient(low = "white", high="red") + 
  ylab("")+xlab("") +
  theme(
    # Remove panel border
    panel.border = element_blank(),  
    # Remove panel grid lines
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    # Remove panel background
    panel.background = element_blank(),
    axis.text.x = element_text(size=fontSize),
    axis.text.y = element_text(size=fontSize),
    axis.title.x = element_text(size=fontSize),
    strip.text.x = element_text(size=fontSize),
    axis.title.y = element_text(size=fontSize),
    plot.title = element_text(hjust = 0.5, size=fontSize))
    
ggsave(filename = file.path(plotdir, "GCLUST_SA_sexAdj_LV1_MEcorr.pdf"), width=5,height=5)
p

#------------------------------------------------------------------------------





#------------------------------------------------------------------------------
sa_allVert_data = read.csv(file.path(plspath,"results","plsres_all_sa_allVertices_sexMeanSAAdj_MEcorr_bootCI4plotting_LV1_ci95.csv"))
# sa_good = subset(sa_data,sa_data$Grp=="Good")
# sa_poor = subset(sa_data,sa_data$Grp=="Poor")
# sa_td = subset(sa_data,sa_data$Grp=="TD")

fontSize = 18
data4heatmap = sa_allVert_data
data4heatmap$corr = data4heatmap$corr*-1
me_corr_comp$allVertices = data4heatmap$corr
level_ordering = rev(c("M13","M2","M16","M21","M4","M10","M6","M7","M11","M15",
                   "M20","M3","M17","M5","M19","M14","M12","M9","M8","M18","M1"))
data4heatmap$ModName = factor(data4heatmap$ModName, 
                              levels = level_ordering)
data4heatmap$Grp = factor(data4heatmap$Grp, levels = c("Poor","Good","TD")) 
p = ggplot(data = data4heatmap) + 
  geom_tile(aes(y = ModName, x = Grp, fill= corr)) + 
  geom_text(aes(y= ModName, x=Grp, label = round(corr,2)),size = 5) + 
  scale_fill_gradientn(colors = colorRampPalette(c("blue","white","red"))(100), limits=c(-0.8,0.8)) +
  # scale_fill_gradient(low = "white", high="red") + 
  ylab("")+xlab("") +
  theme(
    # Remove panel border
    panel.border = element_blank(),  
    # Remove panel grid lines
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    # Remove panel background
    panel.background = element_blank(),
    axis.text.x = element_text(size=fontSize),
    axis.text.y = element_text(size=fontSize),
    axis.title.x = element_text(size=fontSize),
    strip.text.x = element_text(size=fontSize),
    axis.title.y = element_text(size=fontSize),
    plot.title = element_text(hjust = 0.5, size=fontSize))
    
ggsave(filename = file.path(plotdir, "AllVertices_SA_sexMeanSAAdj_LV1_MEcorr.pdf"), width=5,height=5)
p

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
grp_names = unique(me_corr_comp$Grp)
r_mat = data.frame(matrix(nrow = length(grp_names), ncol =  2))
rownames(r_mat) = grp_names
colnames(r_mat) = c("corr","pval")
tmp_res = cor.test(me_corr_comp$gclust[me_corr_comp$Grp=="Poor"],me_corr_comp$allVertices[me_corr_comp$Grp=="Poor"])
r_mat["Poor","corr"] = tmp_res$estimate
r_mat["Poor","pval"] = tmp_res$p.value
tmp_res = cor.test(me_corr_comp$gclust[me_corr_comp$Grp=="Good"],me_corr_comp$allVertices[me_corr_comp$Grp=="Good"])
r_mat["Good","corr"] = tmp_res$estimate
r_mat["Good","pval"] = tmp_res$p.value
tmp_res = cor.test(me_corr_comp$gclust[me_corr_comp$Grp=="TD"],me_corr_comp$allVertices[me_corr_comp$Grp=="TD"])
r_mat["TD","corr"] = tmp_res$estimate
r_mat["TD","pval"] = tmp_res$p.value
r_mat$Grp = rownames(r_mat)
r_mat$x_var = "corr"

p = ggplot(data = r_mat) + 
  geom_tile(aes(y = Grp, x = x_var, fill= corr)) + 
  geom_text(aes(y= Grp, x = x_var, label = round(corr,2)),size = 5) + 
  scale_fill_gradientn(colors = colorRampPalette(c("blue","white","red"))(100), limits=c(-1,1)) +
  # scale_fill_gradient(low = "white", high="red") + 
  ylab("")+xlab("") +
  theme(
    # Remove panel border
    panel.border = element_blank(),  
    # Remove panel grid lines
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    # Remove panel background
    panel.background = element_blank(),
    axis.text.x = element_text(size=fontSize),
    axis.text.y = element_text(size=fontSize),
    axis.title.x = element_text(size=fontSize),
    strip.text.x = element_text(size=fontSize),
    axis.title.y = element_text(size=fontSize),
    plot.title = element_text(hjust = 0.5, size=fontSize))
    
ggsave(filename = file.path(plotdir, "GCLUST_AllVertices_SA_LV1_MEcorr_comp.pdf"), width=3,height=5)
r_mat
##           corr         pval  Grp x_var
## Good 0.9568105 1.202089e-11 Good  corr
## Poor 0.6099266 3.326922e-03 Poor  corr
## TD   0.6550045 1.270730e-03   TD  corr
p

#------------------------------------------------------------------------------







# Surface Area
df2plot = data.frame(Good = sa_good$corr, Poor = sa_poor$corr, TD = sa_td$corr, ModName = sa_poor$ModName)

df2plot$modtype = NA
df2plot$modtype[c(2,4,6,7,16,20,21)] = "PosNonZero"
df2plot$modtype[c(1,11,14,18)] = "NegNonZero"

# p1 = ggplot(data = df2plot, aes(x = Good, y = Poor, label=ModName))
p1 = ggplot(data = df2plot, aes(x = Good, y = Poor))
p1 = p1 + geom_point(data=df2plot, aes(fill=modtype), size=dotSize, colour="black", pch=21) +
  # geom_text(colour="black") +
  geom_smooth(method=lm, colour="black")
p1 = p1 + xlab("ASD Good PLS Correlation") + ylab("ASD Poor PLS Correlation") + guides(colour=FALSE, fill=FALSE) +
  ggtitle("ASD Good vs ASD Poor") +
  scale_fill_manual(values = c("dark blue","dark red")) +
  theme(text = element_text(size=fontSize), 
        axis.text.x = element_text(size=fontSize),
        axis.text.y = element_text(size=fontSize),
        plot.title = element_text(size=fontSize,hjust=0.5))
ggsave(filename = file.path(plotdir, "plscorr_scatterplot_ASDGood_ASDPoor_SA_LV1.pdf"))
p1

cor.test(df2plot$Good, df2plot$Poor)
## 
##  Pearson's product-moment correlation
## 
## data:  df2plot$Good and df2plot$Poor
## t = 1.2397, df = 19, p-value = 0.2302
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1792977  0.6307610
## sample estimates:
##      cor 
## 0.273563
df2plot$modtype = NA
df2plot$modtype[c(2,10,13,16,21)] = "PosNonZero"
df2plot$modtype[c(1,11)] = "NegNonZero"

# p2 = ggplot(data = df2plot, aes(x = TD, y = Poor, label=ModName))
p2 = ggplot(data = df2plot, aes(x = TD, y = Poor))
p2 = p2 + geom_point(data=df2plot, aes(fill=modtype), size=dotSize, colour="black", pch=21) +
  # geom_text(colour="black") +
  geom_smooth(method=lm, colour="black")
p2 = p2 + xlab("TD PLS Correlation") + ylab("ASD Poor PLS Correlation") + guides(colour=FALSE, fill=FALSE) + 
  ggtitle("TD vs ASD Poor") +
  scale_fill_manual(values = c("dark blue","dark red")) +
  theme(text = element_text(size=fontSize), 
        axis.text.x = element_text(size=fontSize),
        axis.text.y = element_text(size=fontSize),
        plot.title = element_text(size=fontSize,hjust=0.5))
ggsave(filename = file.path(plotdir, "plscorr_scatterplot_TD_ASDPoor_SA_LV1.pdf"))
p2

cor.test(df2plot$TD, df2plot$Poor)
## 
##  Pearson's product-moment correlation
## 
## data:  df2plot$TD and df2plot$Poor
## t = -1.9913, df = 19, p-value = 0.06102
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.71835850  0.01968846
## sample estimates:
##      cor 
## -0.41553
df2plot$modtype = NA
df2plot$modtype[c(2,4,6,7,10,13,16,20,21)] = "PosNonZero"
df2plot$modtype[c(1,14,18)] = "NegNonZero"

# p3 = ggplot(data = df2plot, aes(x = TD, y = Good, label=ModName))
p3 = ggplot(data = df2plot, aes(x = TD, y = Good))
p3 = p3 + geom_point(data=df2plot, aes(fill=modtype), size=dotSize, colour="black", pch=21) +
  # geom_text(colour="black") +
  geom_smooth(method=lm, colour="black")
p3 = p3 + xlab("TD PLS Correlation") + ylab("ASD Good PLS Correlation") + guides(colour=FALSE, fill=FALSE) + 
  ggtitle("TD vs ASD Good") +
  scale_fill_manual(values = c("dark blue","dark red")) +
  theme(text = element_text(size=fontSize), 
        axis.text.x = element_text(size=fontSize),
        axis.text.y = element_text(size=fontSize),
        plot.title = element_text(size=fontSize,hjust=0.5))
ggsave(filename = file.path(plotdir, "plscorr_scatterplot_TD_ASDGood_SA_LV1.pdf"))
p3

cor.test(df2plot$TD, df2plot$Good)
## 
##  Pearson's product-moment correlation
## 
## data:  df2plot$TD and df2plot$Good
## t = 2.9271, df = 19, p-value = 0.008648
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1656717 0.7972970
## sample estimates:
##       cor 
## 0.5574879
p_final = (p1 | p2 | p3)
p_final

Examine enrichment at the gene-level between gene classes and non-zero or zero modules

geneclasses = c("BroadGenesVG","BrainGenesVG")
res_colnames = c("Non-Zero Modules","Zero Modules")

ORmat = data.frame(matrix(nrow = length(geneclasses), 
                          ncol = length(res_colnames)))
logPmat = data.frame(matrix(nrow = length(geneclasses), 
                            ncol = length(res_colnames)))
Pmat = data.frame(matrix(nrow = length(geneclasses),
                         ncol = length(res_colnames)))
FDRmat = data.frame(matrix(nrow = length(geneclasses),
                           ncol = length(res_colnames)))
NOverlapmat = data.frame(matrix(nrow = length(geneclasses), 
                          ncol = length(res_colnames)))

colnames(ORmat) = res_colnames
colnames(logPmat) = res_colnames
colnames(Pmat) = res_colnames
colnames(FDRmat) = res_colnames
colnames(NOverlapmat) = res_colnames
rownames(ORmat) = geneclasses
rownames(logPmat) = geneclasses
rownames(Pmat) = geneclasses
rownames(FDRmat) = geneclasses
rownames(NOverlapmat) = geneclasses

for (i in 1:length(geneclasses)){
  # intersect genes2 with background list
  genes2 = eval(as.name(geneclasses[i]))
  mask = is.element(genes2,bglist)
  genes2 = data.frame(genes2[mask])
  
  overlap_res = genelistOverlap(nz_genes,
                                genes2,
                                backgroundTotal,
                                print_result = FALSE,
                                header = FALSE)
  ORmat[i,1] = overlap_res[[1]]$OR
  logPmat[i,1] = -log10(overlap_res[[1]]$hypergeo_p)
  Pmat[i,1] = overlap_res[[1]]$hypergeo_p
  NOverlapmat[i,1] = overlap_res[[1]]$gene_overlap

  overlap_res = genelistOverlap(z_genes,
                                genes2,
                                backgroundTotal,
                                print_result = FALSE,
                                header = FALSE)
  ORmat[i,2] = overlap_res[[1]]$OR
  logPmat[i,2] = -log10(overlap_res[[1]]$hypergeo_p)
  Pmat[i,2] = overlap_res[[1]]$hypergeo_p
  NOverlapmat[i,2] = overlap_res[[1]]$gene_overlap
}
for (i in 1:dim(Pmat)[2]){
  FDRmat[,i] = p.adjust(Pmat[,i], method = "fdr")
}

zLIM = c(0,30)
par(mar = c(6, 8.5, 3, 3))
WGCNA::labeledHeatmap(Matrix = logPmat,
                      xLabels = colnames(ORmat), 
                      yLabels = rownames(ORmat),
                      ySymbols = NULL, 
                      colorLabels = FALSE,
                      colors = WGCNA::blueWhiteRed(100), 
                      textMatrix = round(ORmat, digits = 2),
                      setStdMargins = FALSE, 
                      cex.text = 3, 
                      zlim = zLIM)

# Enrichment Odds Ratios
ORmat
##              Non-Zero Modules Zero Modules
## BroadGenesVG         3.482644    1.1077709
## BrainGenesVG         1.676564    0.9434521
# P-values
Pmat
##              Non-Zero Modules Zero Modules
## BroadGenesVG     1.903419e-71    0.9999644
## BrainGenesVG     2.384893e-01    0.9999393
# FDR
FDRmat
##              Non-Zero Modules Zero Modules
## BroadGenesVG     3.806839e-71    0.9999644
## BrainGenesVG     2.384893e-01    0.9999644
# Noverlap
NOverlapmat
##              Non-Zero Modules Zero Modules
## BroadGenesVG             2685          898
## BrainGenesVG              767          281

All enrichments

geneclasses = list(HumanSpecific_Prenatal_Zhu,
                   HumanSpecific_EarlyPostnatal_Zhu,
                   HumanSpecific_Adult_Zhu,
                   won_har_genes,
                   won_hge_fetal_genes,
                   won_hge_adult_genes,
                   won_hle_genes,
                   W234_PC1,
                   W234_PC2,
                   SongBirdDE,
                   ASDPrenatal1,
                   gandal_asd_down,
                   gandal_asd_up,
                   ASDCTXDownreg,
                   ASDCTXUpreg,
                   ASD102,
                   SFARIASD,
                   FMRP1,
                   FMRP2,
                   CHD81,
                   CHD82,
                   gandal_scz,
                   gandal_bd,
                   excitatory_de_genes,
                   inhibitory_de_genes,
                   microglia_de_genes,
                   oligodendrocyte_de_genes,
                   astrocyte_de_genes,
                   endothelial_de_genes,
                   vRG,oRG,PgS,PgG2M,IP,
                   ExN,ExM,ExMU,ExDp1,ExDp2,
                   InMGE,InCGE,
                   OPC,End,Per,Mic)

geneclassnames = c("Human-Specific Prenatal",
                   "Human-Specific Early Postnatal",
                   "Human-Specific Adult",
                   "Human-Accelerated Genes",
                   "Human-Gained Enhancers Fetal",
                   "Human-Gained Enhancers Adult",
                   "Human-Lossed Enhancers",
                   "PC1",
                   "PC2",
                   "Song Bird DE",
                   "ASD Prenatal1",
                   "ASD DE Downreg",
                   "ASD DE Upreg",
                   "ASD CTX Downreg",
                   "ASD CTX Upreg",
                   "ASD 102 dnPTVs",
                   "SFARI ASD",
                   "FMRP Targets1",
                   "FMRP Targets2",
                   "CHD8 Targets1",
                   "CHD8 Targets2",
                   "SCZ DE",
                   "BD DE",
                   "ASD Excitatory",
                   "ASD Inhibitory",
                   "ASD Microglia",
                   "ASD Oligodendrocyte",
                   "ASD Astrocyte",
                   "ASD Endothelial",
                   "Ventricular Radial Glia",
                   "Outer Radial Glia",
                   "Cycling Progenitors S phase",
                   "Cycling Progenitors G2M phase",
                   "Intermediate Progenitors",
                   "Migrating Excitatory",
                   "Maturing Excitatory",
                   "Maturing Excitatory Upper Enriched",
                   "Excitatory Deep Layer 1",
                   "Excitatory Deep Layer 2",
                   "Interneuron MGE",
                   "Interneuron CGE",
                   "Oligodendrocyte Precursor Cells",
                   "Endothelial",
                   "Pericyte",
                   "Microglia")

res_colnames =  c("Non-Zero Modules","Zero Modules")
ORmat = data.frame(matrix(nrow = length(geneclasses), 
                          ncol = length(res_colnames)))
logPmat = data.frame(matrix(nrow = length(geneclasses), 
                            ncol = length(res_colnames)))
Pmat = data.frame(matrix(nrow = length(geneclasses), 
                         ncol = length(res_colnames)))
FDRmat = data.frame(matrix(nrow = length(geneclasses), 
                           ncol = length(res_colnames)))
colnames(ORmat) = res_colnames
colnames(logPmat) = res_colnames
colnames(Pmat) = res_colnames
colnames(FDRmat) = res_colnames
rownames(ORmat) = geneclassnames
rownames(logPmat) = geneclassnames
rownames(Pmat) = geneclassnames
rownames(FDRmat) = geneclassnames

tmp_cols = c("PROBE_ID","geneSymbol","moduleLabels","moduleColors","NonZeroMod",geneclassnames)
enrich_res_table = data.frame(matrix(nrow = dim(wgcna_res)[1], ncol = length(tmp_cols)))
colnames(enrich_res_table) = tmp_cols
enrich_res_table[,tmp_cols[1:4]] = wgcna_res[,tmp_cols[1:4]]
enrich_res_table[,"NonZeroMod"] = 0
enrich_res_table[is.element(enrich_res_table$moduleLabels,nonzeromods),"NonZeroMod"] = 1

for (i in 1:length(geneclasses)){
  # intersect with background list
  genes2 = geneclasses[[i]]
  mask = is.element(genes2,bglist)
  genes2 = data.frame(genes2[mask])

  overlap_res = genelistOverlap(nz_genes,
                                genes2,
                                backgroundTotal,
                                print_result = FALSE,
                                header = FALSE)
  ORmat[i,"Non-Zero Modules"] = overlap_res[[1]]$OR
  logPmat[i,"Non-Zero Modules"] = -log10(overlap_res[[1]]$hypergeo_p)
  Pmat[i,"Non-Zero Modules"] = overlap_res[[1]]$hypergeo_p
  
  genes2export = unique(as.character(overlap_res[[1]]$overlapping_genes))
  write(genes2export, 
        file = file.path(here("results",sprintf("%s_nonzero_overlap_SALV1.txt",geneclassnames[i]))))

  mask = is.element(enrich_res_table$geneSymbol,genes2export)
  enrich_res_table[, geneclassnames[i]] = 0
  enrich_res_table[mask, geneclassnames[i]] = 1
  
  # if (is.element(geneclassnames[i],c("PC1","PC2"))){
  #   genes2export = unique(as.character(overlap_res[[1]]$overlapping_genes))
  #   write(genes2export, 
  #         file = file.path(here("results",sprintf("%s_nonzero_overlap_SALV1.txt",geneclassnames[i]))))
  # }
  # 
  # if (is.element(geneclassnames[i],c("ASD CTX Downreg","ASD Prenatal1","FMRP Targets1",
  #                                  "FMRP Targets2","CHD8 Targets1","CHD8 Targets2",
  #                                  "Ventricular Radial Glia",
  #                                  "Outer Radial Glia",
  #                                  "Cycling Progenitors S phase",
  #                                  "Cycling Progenitors G2M phase",
  #                                  "Intermediate Progenitors",
  #                                  "Maturing Excitatory","Maturing Excitatory Upper Enriched",
  #                                  "Excitatory Deep Layer 1","Interneuron MGE","Song Bird DE"))){
  #   genes2export = unique(as.character(overlap_res[[1]]$overlapping_genes))
  #   write(genes2export, 
  #         file = file.path(here("results",sprintf("%s_nonzero_overlap_CTLV2.txt",geneclassnames[i]))))
  # }

  
  overlap_res = genelistOverlap(z_genes,
                                genes2,
                                backgroundTotal,
                                print_result = FALSE,
                                header = FALSE)
  ORmat[i,"Zero Modules"] = overlap_res[[1]]$OR
  logPmat[i,"Zero Modules"] = -log10(overlap_res[[1]]$hypergeo_p)
  Pmat[i,"Zero Modules"] = overlap_res[[1]]$hypergeo_p
}
for (i in 1:dim(Pmat)[2]){
  FDRmat[,i] = p.adjust(Pmat[,i], method = "fdr")
}

write.csv(enrich_res_table, file = here("results","enrich_res_table_SALV1.csv"))

Enrichment with Song Bird DE genes

geneclassnames = c("Song Bird DE")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# Enrichment Odds Ratios
ORmat2use
##              Non-Zero Modules Zero Modules
## Song Bird DE         2.027822     1.271512
# P-values
Pmat2use
##              Non-Zero Modules Zero Modules
## Song Bird DE     0.0001057592    0.2689112
# FDR
FDRmat2use
##              Non-Zero Modules Zero Modules
## Song Bird DE     0.0003399403    0.7353366

Enrichment with human-specific genes

geneclassnames = c("Human-Specific Prenatal",
                   "Human-Specific Early Postnatal",
                   "Human-Specific Adult",
                   "Human-Accelerated Genes",
                   "Human-Gained Enhancers Fetal",
                   "Human-Gained Enhancers Adult",
                   "Human-Lossed Enhancers")

studyname = c("Zhu et al., 2018",
              "Zhu et al., 2018",
              "Zhu et al., 2018",
              "Won et al., 2019",
              "Won et al., 2019",
              "Won et al., 2019",
              "Won et al., 2019")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# make figure
pheatmap(logPmat2use, display_numbers = round(ORmat2use,digits=2), 
         number_color = "black", fontsize_number = 12,
         show_rownames=TRUE,
         labels_col = res_colnames,
         color = colorRampPalette(c('light blue','white','red'))(100),
         cluster_rows = FALSE, cluster_cols = FALSE,
         breaks= seq(0,-log10(0.005), length=100))

mat2use = logPmat2use
mat2use$labels = rownames(mat2use)
mat2use$cat = factor(studyname)
df4plot = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels","cat")])
mat2use = ORmat2use
mat2use$labels = rownames(mat2use)
tmp = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
df4plot$OR = tmp$value
df4plot$labels = factor(df4plot$labels, levels = rev(geneclassnames))
df4plot$cat = factor(df4plot$cat, levels = rev(unique(studyname)))

p = ggplot(data = df4plot, aes(x = labels, y = value, fill=cat)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.05)) +
  coord_flip() #+ 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
p

fs2use = fontSize-5
p = ggplot(data = df4plot, aes(x = labels, y = value, fill=OR)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity", colour="black") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.01), linetype="dashed") +
  scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100), 
                       limits = c(min(df4plot$OR),max(df4plot$OR))) +
  coord_flip() + 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
  theme(axis.text.x = element_text(size=fs2use),
        # axis.text.y = element_text(size=fs2use),
        axis.title.x = element_text(size=fs2use),
        strip.text.x = element_text(size=fs2use),
        plot.title = element_text(size=fs2use,hjust=0.5))
ggsave(filename = file.path(plotdir,"humanspecific_enrichment_SA_LV1.pdf"))
p

# Enrichment Odds Ratios
ORmat2use
##                                Non-Zero Modules Zero Modules
## Human-Specific Prenatal                1.861890    1.0663144
## Human-Specific Early Postnatal         1.757550    1.0386328
## Human-Specific Adult                   1.979902    1.0453592
## Human-Accelerated Genes                1.742303    1.3233811
## Human-Gained Enhancers Fetal           2.027047    0.5351976
## Human-Gained Enhancers Adult           1.773764    1.0830553
## Human-Lossed Enhancers                 1.794104    0.9680589
# P-values
Pmat2use
##                                Non-Zero Modules Zero Modules
## Human-Specific Prenatal            1.937200e-03    0.9580686
## Human-Specific Early Postnatal     4.259132e-02    0.9491229
## Human-Specific Adult               1.023159e-05    0.9948661
## Human-Accelerated Genes            1.238795e-01    0.2262480
## Human-Gained Enhancers Fetal       1.340579e-01    0.9874484
## Human-Gained Enhancers Adult       7.619535e-02    0.7850607
## Human-Lossed Enhancers             5.510986e-02    0.9535322
# FDR
FDRmat2use
##                                Non-Zero Modules Zero Modules
## Human-Specific Prenatal            4.358701e-03    0.9999925
## Human-Specific Early Postnatal     6.608998e-02    0.9999925
## Human-Specific Adult               3.541705e-05    0.9999925
## Human-Accelerated Genes            1.548494e-01    0.7272256
## Human-Gained Enhancers Fetal       1.630434e-01    0.9999925
## Human-Gained Enhancers Adult       1.071497e-01    0.9999925
## Human-Lossed Enhancers             7.999819e-02    0.9999925

Enrichment in prenatal gradient expression

geneclassnames = c("PC1",
                   "PC2")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# make figure
pheatmap(logPmat2use, display_numbers = round(ORmat2use,digits=2), 
         number_color = "black", fontsize_number = fontSize,
         show_rownames=TRUE,
         labels_col = res_colnames,
         color = colorRampPalette(c('light blue','white','red'))(100),
         cluster_rows = FALSE, cluster_cols = FALSE,
         fontsize_row = fontSize, fontsize_col = fontSize,
         breaks= seq(0,-log10(0.005), length=100))

mat2use = logPmat2use
mat2use$labels = rownames(mat2use)
df4plot = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
mat2use = ORmat2use
mat2use$labels = rownames(mat2use)
tmp = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
df4plot$OR = tmp$value
df4plot$labels = factor(df4plot$labels, levels = rev(geneclassnames))

p = ggplot(data = df4plot, aes(x = labels, y = value)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.05)) +
  coord_flip() #+ 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
p = p +  theme(text = element_text(size=fontSize), 
        axis.text.x = element_text(size=fontSize),
        axis.text.y = element_text(size=fontSize))
p

# Enrichment Odds Ratios
ORmat2use
##     Non-Zero Modules Zero Modules
## PC1         2.695846    0.9971211
## PC2         2.869637    1.0189664
# P-values
Pmat2use
##     Non-Zero Modules Zero Modules
## PC1     1.264299e-33    0.9999895
## PC2     7.117349e-43    0.9999925
# FDR
FDRmat2use
##     Non-Zero Modules Zero Modules
## PC1     1.896448e-32    0.9999925
## PC2     3.202807e-41    0.9999925

Examine enrichment between non-zero or zero modules and song bird DE, Human Specific, ASD Prenatal, ASD CTX Dysregulated Modules, ASD PTVs, ASD SFARI, and FMRP and CHD8 targets

geneclassnames = c("ASD 102 dnPTVs",
                   "SFARI ASD",
                   "ASD DE Downreg",
                   "ASD DE Upreg",
                   "ASD CTX Downreg",
                   "ASD CTX Upreg",
                   "ASD Prenatal1",
                   "FMRP Targets1",
                   "FMRP Targets2",
                   "CHD8 Targets1",
                   "CHD8 Targets2",
                   "SCZ DE",
                   "BD DE")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# make figure
pheatmap(logPmat2use, display_numbers = round(ORmat2use,digits=2), 
         number_color = "black", fontsize_number = 12,
         show_rownames=TRUE,
         labels_col = res_colnames,
         color = colorRampPalette(c('light blue','white','red'))(100),
         cluster_rows = FALSE, cluster_cols = FALSE,
         breaks= seq(0,-log10(0.005), length=100))

mat2use = logPmat2use
mat2use$labels = rownames(mat2use)
df4plot = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
mat2use = ORmat2use
mat2use$labels = rownames(mat2use)
tmp = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
df4plot$OR = tmp$value
df4plot$labels = factor(df4plot$labels, levels = rev(geneclassnames))

p = ggplot(data = df4plot, aes(x = labels, y = value)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.05)) +
  coord_flip() #+ 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
p

fs2use = fontSize-5
p = ggplot(data = df4plot, aes(x = labels, y = value, fill=OR)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity", colour="black") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.01), linetype="dashed") +
  scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100), 
                       limits = c(min(df4plot$OR),max(df4plot$OR))) +
  ylim(0,42) + 
  coord_flip() + 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
  theme(axis.text.x = element_text(size=fs2use),
        # axis.text.y = element_text(size=fs2use),
        axis.title.x = element_text(size=fs2use),
        strip.text.x = element_text(size=fs2use),
        plot.title = element_text(size=fs2use,hjust=0.5))
ggsave(filename = file.path(plotdir,"asdgenelist_enrichment_SA_LV1.pdf"))
p

# Enrichment Odds Ratios
ORmat2use
##                 Non-Zero Modules Zero Modules
## ASD 102 dnPTVs          1.941935    0.8773216
## SFARI ASD               1.802044    1.0035060
## ASD DE Downreg          1.891583    1.1120901
## ASD DE Upreg            2.177891    1.7506987
## ASD CTX Downreg         1.988391    0.9071381
## ASD CTX Upreg           1.846795    1.7275377
## ASD Prenatal1           2.367159    0.8666482
## FMRP Targets1           2.437915    0.7347917
## FMRP Targets2           2.354752    1.4096707
## CHD8 Targets1           2.501138    1.1002091
## CHD8 Targets2           2.857467    1.0443434
## SCZ DE                  2.157613    1.2516533
## BD DE                   1.630222    1.3250078
# P-values
Pmat2use
##                 Non-Zero Modules Zero Modules
## ASD 102 dnPTVs      1.845038e-01 8.436208e-01
## SFARI ASD           4.541149e-02 9.268890e-01
## ASD DE Downreg      2.074753e-02 7.122944e-01
## ASD DE Upreg        1.260561e-04 5.338003e-04
## ASD CTX Downreg     2.876274e-03 9.850967e-01
## ASD CTX Upreg       1.433097e-02 7.894146e-05
## ASD Prenatal1       2.407864e-12 9.999503e-01
## FMRP Targets1       2.689136e-07 9.998277e-01
## FMRP Targets2       1.221707e-03 1.898297e-01
## CHD8 Targets1       4.762385e-21 9.454243e-01
## CHD8 Targets2       9.966104e-42 9.999674e-01
## SCZ DE              1.950031e-10 3.727167e-01
## BD DE               2.866176e-01 1.791875e-01
# FDR
FDRmat2use
##                 Non-Zero Modules Zero Modules
## ASD 102 dnPTVs      2.128890e-01  0.999992481
## SFARI ASD           6.811724e-02  0.999992481
## ASD DE Downreg      3.590919e-02  0.999992481
## ASD DE Upreg        3.781684e-04  0.008007004
## ASD CTX Downreg     5.627492e-03  0.999992481
## ASD CTX Upreg       2.579574e-02  0.003552366
## ASD Prenatal1       1.354423e-11  0.999992481
## FMRP Targets1       1.100101e-06  0.999992481
## FMRP Targets2       3.233932e-03  0.657102901
## CHD8 Targets1       4.286147e-20  0.999992481
## CHD8 Targets2       2.242373e-40  0.999992481
## SCZ DE              9.750153e-10  0.840000727
## BD DE               3.070903e-01  0.657102901

Examine enrichment between ASD DE cell-type lists (Velmeshev et al.,)

geneclassnames = c("ASD Excitatory",
                   "ASD Inhibitory",
                   "ASD Microglia",
                   "ASD Oligodendrocyte",
                   "ASD Astrocyte",
                   "ASD Endothelial")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# make figure
pheatmap(logPmat2use, display_numbers = round(ORmat2use,digits=2), 
         number_color = "black", fontsize_number = 12,
         show_rownames=TRUE,
         labels_col = res_colnames,
         color = colorRampPalette(c('light blue','white','red'))(100),
         cluster_rows = FALSE, cluster_cols = FALSE,
         breaks= seq(0,-log10(0.005), length=100))

mat2use = logPmat2use
mat2use$labels = rownames(mat2use)
df4plot = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
mat2use = ORmat2use
mat2use$labels = rownames(mat2use)
tmp = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
df4plot$OR = tmp$value

fs2use = fontSize-5
df4plot$labels = factor(df4plot$labels, levels = rev(geneclassnames))
p = ggplot(data = df4plot, aes(x = labels, y = value, fill=OR)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity", colour="black") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.01), linetype="dashed") +
  scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100), 
                       limits = c(min(df4plot$OR),max(df4plot$OR))) +
  ylim(0,3) + 
  coord_flip() + 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
  theme(axis.text.x = element_text(size=fs2use),
        # axis.text.y = element_text(size=fs2use),
        axis.title.x = element_text(size=fs2use),
        strip.text.x = element_text(size=fs2use),
        plot.title = element_text(size=fs2use,hjust=0.5))
ggsave(filename = file.path(plotdir,"asdcelltypes_enrichment_SA_LV1.pdf"))
p

# Enrichment Odds Ratios
ORmat2use
##                     Non-Zero Modules Zero Modules
## ASD Excitatory             1.0596125    0.7413811
## ASD Inhibitory             1.4548400    1.3434037
## ASD Microglia              3.3654820    0.7718658
## ASD Oligodendrocyte        0.8712329    2.8643521
## ASD Astrocyte              2.0359782    0.6224596
## ASD Endothelial            2.2485583    2.2252276
# P-values
Pmat2use
##                     Non-Zero Modules Zero Modules
## ASD Excitatory           0.970056106   0.95943703
## ASD Inhibitory           0.624961438   0.37333366
## ASD Microglia            0.002480906   0.88608692
## ASD Oligodendrocyte      0.878642200   0.13015603
## ASD Astrocyte            0.255198306   0.91593966
## ASD Endothelial          0.150090171   0.07017566
# FDR
FDRmat2use
##                     Non-Zero Modules Zero Modules
## ASD Excitatory           0.970056106    0.9999925
## ASD Inhibitory           0.654029412    0.8400007
## ASD Microglia            0.005316226    0.9999925
## ASD Oligodendrocyte      0.898611341    0.5324565
## ASD Astrocyte            0.280095702    0.9999925
## ASD Endothelial          0.177738361    0.4144282

Examine enrichment between prenatal cell-type lists

geneclassnames = c("Ventricular Radial Glia",
                   "Outer Radial Glia",
                   "Cycling Progenitors S phase",
                   "Cycling Progenitors G2M phase",
                   "Intermediate Progenitors",
                   "Migrating Excitatory",
                   "Maturing Excitatory",
                   "Maturing Excitatory Upper Enriched",
                   "Excitatory Deep Layer 1",
                   "Excitatory Deep Layer 2",
                   "Interneuron MGE",
                   "Interneuron CGE",
                   "Oligodendrocyte Precursor Cells",
                   "Endothelial",
                   "Pericyte",
                   "Microglia")

genetypecat = c("Progenitor",
                "Progenitor",
                "Progenitor",
                "Progenitor",
                "Progenitor",
                "Excitatory",
                "Excitatory",
                "Excitatory",
                "Excitatory",
                "Excitatory",
                "Inhibitory",
                "Inhibitory",
                "Other",
                "Other",
                "Other",
                "Other")

ORmat2use = ORmat[geneclassnames,]
Pmat2use = Pmat[geneclassnames,]
logPmat2use = logPmat[geneclassnames,]
FDRmat2use = FDRmat[geneclassnames,]

# make figure
pheatmap(logPmat2use, display_numbers = round(ORmat2use,digits=2), 
         number_color = "black", fontsize_number = 12,
         show_rownames=TRUE,
         labels_col = res_colnames,
         color = colorRampPalette(c('light blue','white','red'))(100),
         cluster_rows = FALSE, cluster_cols = FALSE,
         breaks= seq(0,-log10(0.005), length=100))

# make bar plot
mat2use = logPmat2use
mat2use$labels = rownames(mat2use)
mat2use$cat = genetypecat
mat2use$labels = factor(mat2use$labels, levels = rev(geneclassnames))
mat2use$cat = factor(mat2use$cat, levels = rev(unique(genetypecat)))
df4plot = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels","cat")])
mat2use = ORmat2use
mat2use$labels = rownames(mat2use)
tmp = melt(mat2use[,c("Non-Zero Modules","Zero Modules","labels")])
df4plot$OR = tmp$value

p = ggplot(data = df4plot, aes(x = labels, y = value, fill=cat)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + 
  geom_hline(yintercept = -log10(0.01)) +
  coord_flip() #+ 
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
p

fs2use = fontSize-5
p = ggplot(data = df4plot, aes(x = labels, y = value, fill=OR)) + facet_grid(. ~ variable)
p = p + geom_bar(stat="identity", colour="black") + 
  ylab("-log10(p-value)") + 
  xlab(" ") + ggtitle("SA LV1") +
  geom_hline(yintercept = -log10(0.01), linetype = "dashed") +
  scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100), 
                       limits = c(min(df4plot$OR),max(df4plot$OR))) +
  ylim(0,30) + 
  coord_flip() +
  # theme(text = element_text(size=fs2use),
  theme(axis.text.x = element_text(size=fs2use),
        # axis.text.y = element_text(size=fs2use),
        axis.title.x = element_text(size=fs2use),
        strip.text.x = element_text(size=fs2use),
        plot.title = element_text(size=fs2use,hjust=0.5))
  # scale_fill_gradientn(colors = colorRampPalette(c("white","red"))(100))
ggsave(filename = file.path(plotdir, "prenatalCellTypes_enrichments_SA_LV1.pdf"))
p

# Enrichment Odds Ratios
ORmat2use
##                                    Non-Zero Modules Zero Modules
## Ventricular Radial Glia                    2.108539    1.6102882
## Outer Radial Glia                          2.147758    1.7041182
## Cycling Progenitors S phase                3.720220    1.0415594
## Cycling Progenitors G2M phase              3.932447    0.9565357
## Intermediate Progenitors                   2.392155    1.3337578
## Migrating Excitatory                       1.940031    1.0480835
## Maturing Excitatory                        2.355677    1.3762499
## Maturing Excitatory Upper Enriched         2.192684    1.1372814
## Excitatory Deep Layer 1                    1.828289    1.4746735
## Excitatory Deep Layer 2                    1.882035    1.3958769
## Interneuron MGE                            2.061853    1.4339981
## Interneuron CGE                            2.011156    0.8976807
## Oligodendrocyte Precursor Cells            2.681489    0.9086132
## Endothelial                                2.075416    1.7245064
## Pericyte                                   2.482869    1.7283126
## Microglia                                  3.457488    1.3997582
# P-values
Pmat2use
##                                    Non-Zero Modules Zero Modules
## Ventricular Radial Glia                2.775231e-03 0.0181985676
## Outer Radial Glia                      5.937467e-04 0.0026542473
## Cycling Progenitors S phase            1.540236e-20 0.8514490206
## Cycling Progenitors G2M phase          1.149742e-18 0.9293938050
## Intermediate Progenitors               1.792397e-03 0.3033142231
## Migrating Excitatory                   2.454356e-01 0.6772099027
## Maturing Excitatory                    6.377631e-03 0.2777938153
## Maturing Excitatory Upper Enriched     2.297073e-02 0.6056498484
## Excitatory Deep Layer 1                8.350139e-02 0.0900410065
## Excitatory Deep Layer 2                2.451093e-02 0.1157974923
## Interneuron MGE                        8.795831e-02 0.2706437352
## Interneuron CGE                        1.105532e-01 0.8523472608
## Oligodendrocyte Precursor Cells        3.559114e-07 0.9580774285
## Endothelial                            1.870407e-03 0.0019157088
## Pericyte                               4.535565e-09 0.0001875457
## Microglia                              2.019680e-23 0.0736761231
# FDR
FDRmat2use
##                                    Non-Zero Modules Zero Modules
## Ventricular Radial Glia                5.627492e-03  0.136489257
## Outer Radial Glia                      1.669913e-03  0.023888226
## Cycling Progenitors S phase            1.155177e-19  0.999992481
## Cycling Progenitors G2M phase          7.391198e-18  0.999992481
## Intermediate Progenitors               4.358701e-03  0.758285558
## Migrating Excitatory                   2.761150e-01  0.999992481
## Maturing Excitatory                    1.195806e-02  0.735336570
## Maturing Excitatory Upper Enriched     3.828456e-02  0.999992481
## Excitatory Deep Layer 1                1.138655e-01  0.450205033
## Excitatory Deep Layer 2                3.939256e-02  0.521088715
## Interneuron MGE                        1.164154e-01  0.735336570
## Interneuron CGE                        1.421399e-01  0.999992481
## Oligodendrocyte Precursor Cells        1.334668e-06  0.999992481
## Endothelial                            4.358701e-03  0.021551724
## Pericyte                               2.041004e-08  0.004219778
## Microglia                              2.272140e-22  0.414428192

Assess enrichments with individual modules

geneclasses = list(HumanSpecific_Prenatal_Zhu,
                   HumanSpecific_EarlyPostnatal_Zhu,
                   HumanSpecific_Adult_Zhu,
                   won_har_genes,
                   won_hge_fetal_genes,
                   won_hge_adult_genes,
                   won_hle_genes,
                   W234_PC1,
                   W234_PC2,
                   SongBirdDE,
                   ASDPrenatal1,
                   gandal_asd_down,
                   gandal_asd_up,
                   ASDCTXDownreg,
                   ASDCTXUpreg,
                   ASD102,
                   SFARIASD,
                   FMRP1,
                   FMRP2,
                   CHD81,
                   CHD82,
                   gandal_scz,
                   gandal_bd,
                   excitatory_de_genes,
                   inhibitory_de_genes,
                   microglia_de_genes,
                   oligodendrocyte_de_genes,
                   astrocyte_de_genes,
                   endothelial_de_genes,
                   vRG,oRG,PgS,PgG2M,IP,
                   ExN,ExM,ExMU,ExDp1,ExDp2,
                   InMGE,InCGE,
                   OPC,End,Per,Mic)

geneclassnames = c("Human-Specific Prenatal",
                   "Human-Specific Early Postnatal",
                   "Human-Specific Adult",
                   "Human-Accelerated Genes",
                   "Human-Gained Enhancers Fetal",
                   "Human-Gained Enhancers Adult",
                   "Human-Lossed Enhancers",
                   "PC1",
                   "PC2",
                   "Song Bird DE",
                   "ASD Prenatal1",
                   "ASD DE Downreg",
                   "ASD DE Upreg",
                   "ASD CTX Downreg",
                   "ASD CTX Upreg",
                   "ASD 102 dnPTVs",
                   "SFARI ASD",
                   "FMRP Targets1",
                   "FMRP Targets2",
                   "CHD8 Targets1",
                   "CHD8 Targets2",
                   "SCZ DE",
                   "BD DE",
                   "ASD Excitatory",
                   "ASD Inhibitory",
                   "ASD Microglia",
                   "ASD Oligodendrocyte",
                   "ASD Astrocyte",
                   "ASD Endothelial",
                   "Ventricular Radial Glia",
                   "Outer Radial Glia",
                   "Cycling Progenitors S phase",
                   "Cycling Progenitors G2M phase",
                   "Intermediate Progenitors",
                   "Migrating Excitatory",
                   "Maturing Excitatory",
                   "Maturing Excitatory Upper Enriched",
                   "Excitatory Deep Layer 1",
                   "Excitatory Deep Layer 2",
                   "Interneuron MGE",
                   "Interneuron CGE",
                   "Oligodendrocyte Precursor Cells",
                   "Endothelial",
                   "Pericyte",
                   "Microglia")

ORmat = data.frame(matrix(nrow = length(mod_names),
                          ncol = length(geneclasses)))
colnames(ORmat) = geneclassnames
rownames(ORmat) = mod_names

Pmat = data.frame(matrix(nrow = length(mod_names),
                         ncol = length(geneclasses)))
colnames(Pmat) = geneclassnames
rownames(Pmat) = mod_names

FDRmat = data.frame(matrix(nrow = length(mod_names),
                           ncol = length(geneclasses)))
colnames(FDRmat) = geneclassnames
rownames(FDRmat) = mod_names

for (imod in 1:length(mod_names)){
  for (igc in 1:length(geneclasses)){
    # intersect geneclass list with background
    genes2 = geneclasses[[igc]]
    mask = is.element(genes2,bglist)
    genes2 = data.frame(genes2[mask])

    modulegenes = wgcna_res$geneSymbol[wgcna_res$moduleLabels==imod]

    overlap_res = genelistOverlap(modulegenes,
                                  genes2,
                                  backgroundTotal,
                                  print_result = FALSE,
                                  header = FALSE)
    ORmat[imod,igc] = overlap_res[[1]]$OR
    Pmat[imod,igc] = overlap_res[[1]]$hypergeo_p
  }
}
for (i in 1:dim(Pmat)[2]){
  FDRmat[,i] = p.adjust(Pmat[,i], method = "fdr")
}

# Enrichment Odds Ratios
ORmat
##     Human-Specific Prenatal Human-Specific Early Postnatal Human-Specific Adult
## M1                1.1132368                      1.1238591            1.1344044
## M2                1.1777173                      1.2799489            1.3759725
## M3                1.0706029                      1.2620357            0.8883251
## M4                1.5367836                      1.2279924            1.5517923
## M5                0.6323972                      0.6472886            0.6335012
## M6                1.5199793                      1.8844683            1.1425708
## M7                1.3175099                      1.1496226            1.3053771
## M8                1.1105825                      1.1887275            0.8597516
## M9                1.1750976                      0.9257732            1.4040835
## M10               0.4456115                      0.5673747            1.0180548
## M11               1.2196126                      1.2008985            1.3800185
## M12               0.4616028                      0.3063472            0.6067416
## M13               1.8676503                      1.5086759            1.4563663
## M14               0.7206041                      0.2251307            0.7997053
## M15               0.8233101                      0.4948072            0.8033923
## M16               0.7600700                      0.6488067            0.8694325
## M17               1.0802160                      1.2399662            1.1311926
## M18               1.4506673                      1.8609779            1.4318157
## M19               1.1441588                      1.1358959            1.1893837
## M20               1.3070363                      1.7072932            1.1954910
## M21               1.4626123                      0.5388963            1.4574988
##     Human-Accelerated Genes Human-Gained Enhancers Fetal
## M1                1.0434343                    1.3786244
## M2                0.6818672                    0.6804173
## M3                1.0980310                    0.0000000
## M4                1.1110284                    2.4213847
## M5                1.5743486                    0.4815262
## M6                1.1420231                    1.7186826
## M7                0.9240883                    0.5546150
## M8                1.3296411                    1.3066837
## M9                0.6130077                    0.0000000
## M10               1.4049038                    0.0000000
## M11               1.8424555                    1.5045083
## M12               0.6833528                    0.7514139
## M13               1.5702998                    2.5857658
## M14               1.9205537                    2.5974661
## M15               1.3371035                    0.0000000
## M16               1.3853495                    0.0000000
## M17               1.0960523                    2.0194202
## M18               1.5716830                    1.0469138
## M19               1.1042258                    0.0000000
## M20               0.8160205                    1.5028278
## M21               0.5610851                    0.0000000
##     Human-Gained Enhancers Adult Human-Lossed Enhancers       PC1       PC2
## M1                     1.4005863              1.2081383 1.2965280 1.3312689
## M2                     0.9068488              0.8452595 1.6709264 1.5917948
## M3                     0.9212996              0.5028175 0.4254575 0.4455956
## M4                     1.0093463              1.1584775 1.9863912 2.3242251
## M5                     0.9901311              0.7741005 1.2064919 1.2257953
## M6                     0.9596594              1.2457597 0.7439276 0.7928571
## M7                     0.9596594              0.4761992 1.4811842 1.8958460
## M8                     0.6951303              2.1051448 1.2403581 1.1429745
## M9                     1.6421638              0.7843513 0.6320782 0.7190808
## M10                    1.5294293              1.6489699 2.0354924 2.1218871
## M11                    0.6836462              1.9340685 1.2438291 1.5713825
## M12                    0.3410716              0.4272263 0.8150297 0.9369811
## M13                    1.6056914              1.7708381 2.0922910 1.5158283
## M14                    1.4687746              1.2372942 2.1884845 1.9808598
## M15                    0.9773119              0.9121475 1.1874750 1.2105523
## M16                    1.3206748              1.6789373 1.2169196 1.0167401
## M17                    0.6059710              1.0123834 0.7431452 0.6516781
## M18                    1.1477733              1.2338626 1.2414780 1.3756739
## M19                    1.5276575              0.5120890 0.9859597 0.9255865
## M20                    0.4538182              0.2097982 1.5554365 1.7997589
## M21                    0.7171249              0.4417909 1.8455701 2.2184071
##     Song Bird DE ASD Prenatal1 ASD DE Downreg ASD DE Upreg ASD CTX Downreg
## M1     1.3375342     1.2665346      0.8239400    2.2553876       1.0472613
## M2     0.9105077     0.6434830      1.5258927    0.8537522       1.0477397
## M3     0.9493592     1.1722718      1.0185873    0.4173641       0.6707316
## M4     0.9500158     0.1228903      1.8233211    0.3473206       1.7459433
## M5     1.5392690     0.3763681      1.3671554    0.5974917       0.9124949
## M6     0.7562689     0.2432538      0.7586843    1.0568188       0.5518329
## M7     1.4511140     0.2120242      1.9126333    0.4247354       1.4094346
## M8     1.2498427     0.2827933      0.7672684    1.6795633       1.0300270
## M9     0.5642168     0.4147352      0.2238206    7.0409095       0.4763636
## M10    1.5970249     9.0323937      1.0541437    0.8471897       3.3208439
## M11    0.8866549     0.7260928      1.1535097    0.4521034       1.1917667
## M12    0.6970902     0.5082274      0.3761643    0.2269324       0.2086184
## M13    1.8291349     2.9622875      1.4579205    1.3256290       1.7499213
## M14    2.5780061     7.0728335      0.5621078    2.2205765       0.9653950
## M15    1.2578359     2.8326377      1.7454432    1.1295863       1.4566038
## M16    0.9537124     0.9869081      1.2866348    1.4844283       0.9338711
## M17    1.2109172     0.6805078      1.3790450    0.9266119       1.0005762
## M18    0.5200005     0.5929365      1.0771484    2.0566833       0.5911785
## M19    1.2583705     0.4695838      1.0260495    1.3305233       1.0385794
## M20    1.6035872     1.5866473      2.1333944    0.9303615       1.7822678
## M21    2.3342532     2.2724183      2.5356430    1.4874560       1.1267034
##     ASD CTX Upreg ASD 102 dnPTVs SFARI ASD FMRP Targets1 FMRP Targets2
## M1      2.4256767      1.4435490 1.3002438    1.56260898     1.6157005
## M2      0.5597165      0.3488236 0.4518244    0.19382106     0.4803705
## M3      0.3157409      0.4032140 0.9154303    0.81791849     1.4482154
## M4      0.3236766      0.4730389 0.3634480    0.13050885     0.1597055
## M5      1.0345713      0.5011523 0.5858083    0.27912251     0.6917835
## M6      0.7560540      0.0000000 0.9971901    0.00000000     1.4290536
## M7      0.2805303      0.0000000 0.3687896    0.07927386     0.3927584
## M8      2.1351231      0.6687791 0.7873098    0.86381323     2.1709763
## M9      4.3848560      0.7027027 0.4501403    0.19410225     0.7236972
## M10     1.0083486      3.7838693 2.8866215    7.98794515     1.7531140
## M11     0.3755486      0.0000000 0.3926535    1.35589642     1.0668468
## M12     0.3817051      0.0000000 0.5017957    0.32612570     1.0842647
## M13     0.5998410      0.0000000 0.9077768    1.95697413     2.8343301
## M14     0.9703111      5.7267651 4.4600323    6.07257092     5.4166032
## M15     1.0438195      5.0266106 2.2170578    1.50976562     1.6354828
## M16     1.5158768      1.9661644 1.2872289    0.96770026     0.9964474
## M17     1.3918266      0.0000000 1.2334520    0.88207502     0.7036047
## M18     2.5338198      4.6213280 1.6212372    1.60478448     1.5179706
## M19     2.3179896      0.0000000 0.9813097    0.88905367     0.8543771
## M20     0.9405353      0.0000000 0.5999480    0.65759773     1.6253526
## M21     0.6413981      0.0000000 2.0001924    0.68570020     1.1150345
##     CHD8 Targets1 CHD8 Targets2    SCZ DE     BD DE ASD Excitatory
## M1      1.3221433     0.9735876 1.7161930 1.3916275      0.6191434
## M2      1.1831294     1.7206456 1.0314357 1.7019737      1.6717098
## M3      0.6947457     0.6679055 0.6212525 0.6172295      0.5230994
## M4      0.9456434     2.2586003 0.7769991 0.6103055      0.6139064
## M5      1.6052584     2.0562018 0.9331181 0.4648758      0.0000000
## M6      0.7089355     1.5247056 0.9652261 0.6775443      0.0000000
## M7      1.3000209     3.5344508 0.7360237 0.5369386      0.7495156
## M8      0.6384245     0.3800321 1.2586838 1.2142958      1.7812344
## M9      0.6491459     0.5801498 1.9612071 2.0509100      0.4508822
## M10     2.7294098     1.8954317 1.4622242 0.6591522      0.4525217
## M11     1.7158066     1.7318974 0.9838642 1.4081749      1.0003495
## M12     1.1675201     1.3610393 0.6252518 1.2266129      0.0000000
## M13     1.9583677     2.2816417 1.6582297 1.2524098      0.0000000
## M14     4.6528966     2.9221239 1.0812531 0.6057241      0.5580425
## M15     2.0105699     2.1125080 0.8860674 0.8788697      1.2129842
## M16     0.6759569     0.4151154 1.4987981 1.0314368      1.9095033
## M17     0.5098605     0.3383445 1.3829212 1.9261243      1.3427151
## M18     0.6170034     0.4986443 1.8683426 1.3109881      2.9212245
## M19     0.4171047     0.2248669 1.5748273 1.8525228      0.8028612
## M20     1.8327176     2.1116026 1.5136179 0.5384856      1.0035764
## M21     2.6872466     3.4649912 1.1539066 1.1583144      0.0000000
##     ASD Inhibitory ASD Microglia ASD Oligodendrocyte ASD Astrocyte
## M1       0.7323658     2.5458717           0.6983527     0.8108641
## M2       1.9284802     0.9590924           2.1603717     0.0000000
## M3       0.7029902     0.0000000           0.0000000     0.9067599
## M4       0.8250252     1.3014579           0.0000000     0.0000000
## M5       1.3304267     0.0000000           0.0000000     0.0000000
## M6       0.0000000     0.0000000           0.0000000     0.0000000
## M7       0.4962625     0.0000000           0.0000000     0.0000000
## M8       1.1675962     0.9010031           0.0000000     0.0000000
## M9       0.6041456     0.9467062           0.0000000     0.0000000
## M10      1.8762428     1.9426872           0.0000000     1.5860055
## M11      0.6616833     1.0368687           0.0000000     5.5722581
## M12      0.6723556     2.1550457           4.8434140     0.0000000
## M13      0.7443937     1.1664773           0.0000000     0.0000000
## M14      0.7477318     5.0258741           0.0000000     4.0523649
## M15      3.3718484     0.0000000           0.0000000     2.0968823
## M16      0.8295731     0.0000000           0.0000000     4.4981250
## M17      1.8044668     0.0000000          14.0155566     2.3199549
## M18      3.9498795     4.6225343           0.0000000     5.0826271
## M19      0.0000000     3.4564695           7.7494624     0.0000000
## M20      1.3447112     2.1071848           0.0000000     0.0000000
## M21      1.4012116     2.1957219          10.0938375     3.6651388
##     ASD Endothelial Ventricular Radial Glia Outer Radial Glia
## M1        3.7446200               1.1413671         1.2956781
## M2        0.0000000               1.8069118         0.6887162
## M3        0.7871758               0.6179825         0.4987745
## M4        0.0000000               0.6193648         0.7615201
## M5        0.9783762               1.3590345         1.4890216
## M6        1.1268797               2.2977377         2.5817303
## M7        0.0000000               1.8571899         2.3302690
## M8        4.1637731               1.5060968         2.0142402
## M9        2.8283047               1.7555259         1.6918635
## M10       2.8386269               1.2556026         1.4190152
## M11       0.0000000               0.3291234         0.5396743
## M12       3.1489222               1.2129821         1.2755461
## M13       0.0000000               0.9472835         0.7654065
## M14       1.6978995               0.7555377         1.2566586
## M15       1.8203441               1.2356785         0.9978752
## M16       0.0000000               1.5053419         0.6786813
## M17       0.0000000               1.6128663         1.7007282
## M18       2.1271437               1.1977148         2.2383275
## M19       0.0000000               2.2736587         2.5933726
## M20       0.0000000               3.2734875         2.9651962
## M21       0.0000000               1.0622926         1.1584388
##     Cycling Progenitors S phase Cycling Progenitors G2M phase
## M1                    0.3935776                     0.8067843
## M2                    1.7145908                     0.5030133
## M3                    1.0812357                     0.4967516
## M4                    1.9899011                     1.2060065
## M5                    0.9957732                     1.1666114
## M6                   15.9304653                    19.9834244
## M7                    3.9496646                     3.9725873
## M8                    0.3184035                     0.5461163
## M9                    0.4488786                     0.7223546
## M10                   1.2921545                     0.8757547
## M11                   0.2430105                     0.1541700
## M12                   1.7226614                     1.6680693
## M13                   1.7577968                     1.4612579
## M14                   0.4149331                     0.3510020
## M15                   0.9096157                     0.7645628
## M16                   0.3049782                     0.1932877
## M17                   0.6623992                     0.8472182
## M18                   0.3446081                     0.6660038
## M19                   1.2310132                     0.7661220
## M20                   1.5516973                     1.6373371
## M21                   2.5124348                     2.4482947
##     Intermediate Progenitors Migrating Excitatory Maturing Excitatory
## M1                 0.7286526            1.1435462           1.3133818
## M2                 4.9598677            0.5277125           2.7498969
## M3                 1.5230539            0.6099962           0.0000000
## M4                 0.5691336            0.7156297           0.7241886
## M5                 1.6756248            1.5520294           0.7674519
## M6                 0.9349021            0.0000000           1.1913580
## M7                 2.7319785            1.7883085           0.8846376
## M8                 0.5327223            0.0000000           2.1177168
## M9                 0.0000000            0.0000000           0.3519422
## M10                1.7489257            3.3619359           1.0823039
## M11                0.3038061            0.0000000           0.0000000
## M12                1.2707037            1.1830974           0.3916776
## M13                0.0000000            1.3098579           0.8772038
## M14                0.6934989            0.0000000           1.8032828
## M15                0.0000000            1.4106162           3.5108138
## M16                0.3808912            8.1111111           3.0793331
## M17                1.6828238            1.5606817           3.2980836
## M18                0.8698122            1.6483605           2.2669841
## M19                2.5915144            1.8929559           1.2702366
## M20                4.6950094            0.0000000           1.5903775
## M21                1.9846711            0.0000000           0.8162694
##     Maturing Excitatory Upper Enriched Excitatory Deep Layer 1
## M1                           1.4851557               1.3901412
## M2                           1.3677512               1.2884967
## M3                           0.0000000               0.9340645
## M4                           0.2506931               0.1164305
## M5                           1.3819747               1.1657322
## M6                           0.6181268               0.7289776
## M7                           0.0000000               0.7289776
## M8                           1.0864507               1.5667110
## M9                           0.3724064               0.1729583
## M10                          5.0774148               2.4613881
## M11                          0.0000000               0.0000000
## M12                          0.4144523               0.1924858
## M13                          0.0000000               0.2131093
## M14                          2.4168781               2.0549419
## M15                          2.5945897               3.0223885
## M16                          2.1226976               2.2891839
## M17                          3.4969415               3.0553155
## M18                          1.1699009               0.8193414
## M19                          0.0000000               0.9425103
## M20                          3.4735051               2.4491034
## M21                          1.7548514               2.5565202
##     Excitatory Deep Layer 2 Interneuron MGE Interneuron CGE
## M1                1.2585209       1.0480994       1.1708193
## M2                0.9603253       0.8083258       1.1028433
## M3                0.7493816       0.6155069       0.6219618
## M4                1.1396211       0.3565953       0.7299307
## M5                1.2097047       1.1631494       1.1754751
## M6                0.7747367       1.3407560       0.8911692
## M7                2.3008179       0.4351312       0.8911692
## M8                1.6333197       0.5041520       0.0000000
## M9                0.5815810       0.5297249       0.0000000
## M10               1.5935939       4.7023126       3.4623188
## M11               0.6378631       0.0000000       0.0000000
## M12               1.0576281       0.5895326       0.0000000
## M13               0.0000000       0.0000000       1.3387519
## M14               1.3368589       1.3308257       0.6624289
## M15               2.5046535       2.9434660       0.7102002
## M16               2.2175408       5.5929766       1.4927083
## M17               1.7883487       5.0530583       5.1083393
## M18               1.0998388       1.6691712       2.5713517
## M19               0.4080257       0.0000000       0.0000000
## M20               1.8856317       2.4019780       3.7094909
## M21               0.8074613       1.2286057       1.2413584
##     Oligodendrocyte Precursor Cells Endothelial  Pericyte Microglia
## M1                        1.2568125   2.5551675 1.7284102 3.7709620
## M2                        1.1186514   0.6218384 1.4673890 0.7337367
## M3                        0.3519890   0.3521460 0.5072170 0.6039841
## M4                        1.0685293   0.4989316 2.2445361 0.3738398
## M5                        1.0143440   0.9949531 1.3961125 0.6942748
## M6                        3.2706805   0.6104752 0.6630700 0.5255024
## M7                        1.7354010   0.1990903 1.7016940 0.3904645
## M8                        1.2037620   2.5745810 2.7793191 1.5373217
## M9                        0.9370034   2.8690481 2.3066187 2.8299359
## M10                       1.7841463   1.6940233 0.5614546 1.6270487
## M11                       0.1653987   0.1320081 0.2572255 0.8922794
## M12                       0.5113966   0.4076780 0.7173871 1.0037782
## M13                       0.7613156   0.6065513 0.6928041 0.4887605
## M14                       2.8925128   1.2535337 0.9061444 3.6070685
## M15                       0.4039335   1.8944309 1.2065617 1.5669912
## M16                       1.9918983   1.9638603 2.8468216 1.1292911
## M17                       1.1465113   1.4959298 1.2113067 0.8298423
## M18                       2.2613904   2.0126960 2.6134470 4.7038123
## M19                       1.3970734   2.0773336 1.9808990 1.0136329
## M20                       1.0311768   1.3997802 1.2799263 0.7097655
## M21                       2.2274380   0.5652139 0.7403588 0.9350200
# P-values
Pmat
##     Human-Specific Prenatal Human-Specific Early Postnatal Human-Specific Adult
## M1             0.6800617437                   0.5955244482         0.6591629824
## M2             0.1960758849                   0.1045839388         0.0067252802
## M3             0.4392757585                   0.1330369600         0.9057246687
## M4             0.0032088251                   0.1856949277         0.0005431457
## M5             0.9970581993                   0.9852682016         0.9995259102
## M6             0.0075069866                   0.0004168909         0.2480903154
## M7             0.0707195383                   0.3129950040         0.0480985714
## M8             0.3512091945                   0.2673982308         0.8748416686
## M9             0.2449379868                   0.6917977289         0.0203965284
## M10            0.9998484417                   0.9882672300         0.5388466068
## M11            0.1927812433                   0.2648134036         0.0322256536
## M12            0.9995524542                   0.9998815479         0.9976641975
## M13            0.0005631452                   0.0508657465         0.0178827309
## M14            0.9437886873                   0.9999723952         0.9147926877
## M15            0.8421521059                   0.9905033619         0.9033504860
## M16            0.9041488876                   0.9431953616         0.8131147626
## M17            0.4241894989                   0.2518764123         0.3104227417
## M18            0.0573984660                   0.0078015312         0.0370215321
## M19            0.3412339804                   0.3881713086         0.2417597931
## M20            0.1897364144                   0.0472099035         0.2593180182
## M21            0.0939662146                   0.9520240818         0.0610342747
##     Human-Accelerated Genes Human-Gained Enhancers Fetal
## M1               0.73479958                   0.32474898
## M2               0.94183305                   0.80921147
## M3               0.45137264                   1.00000000
## M4               0.43672790                   0.07155434
## M5               0.06760338                   0.88144542
## M6               0.40768203                   0.27458086
## M7               0.66494252                   0.84256528
## M8               0.24066088                   0.46883704
## M9               0.91453177                   1.00000000
## M10              0.19256032                   1.00000000
## M11              0.03721950                   0.39851685
## M12              0.86164493                   0.74378622
## M13              0.12902422                   0.12228568
## M14              0.03380169                   0.12110260
## M15              0.27522964                   1.00000000
## M16              0.24608953                   1.00000000
## M17              0.48477008                   0.27235491
## M18              0.15917827                   0.62337881
## M19              0.48824832                   1.00000000
## M20              0.71713467                   0.49370424
## M21              0.87274176                   1.00000000
##     Human-Gained Enhancers Adult Human-Lossed Enhancers          PC1
## M1                    0.06855740            0.352933165 5.935403e-02
## M2                    0.74294087            0.828590520 4.197010e-07
## M3                    0.70580818            0.993867013 1.000000e+00
## M4                    0.56848230            0.356743105 5.324010e-10
## M5                    0.59288067            0.857071024 1.021548e-01
## M6                    0.62647865            0.270168000 9.943412e-01
## M7                    0.62647865            0.987228640 1.479568e-03
## M8                    0.88324072            0.002850052 8.417646e-02
## M9                    0.05991156            0.811063602 9.995104e-01
## M10                   0.10125943            0.052203150 5.180103e-08
## M11                   0.87733387            0.013422784 9.248729e-02
## M12                   0.99283286            0.984134653 9.423707e-01
## M13                   0.09350787            0.041078396 2.238980e-07
## M14                   0.15746888            0.319693592 3.820784e-08
## M15                   0.59252176            0.661214775 1.798807e-01
## M16                   0.26963494            0.073456196 1.440780e-01
## M17                   0.89813636            0.555478913 9.690051e-01
## M18                   0.42921018            0.346159424 1.293184e-01
## M19                   0.17599722            0.932383930 5.926816e-01
## M20                   0.93452940            0.991302208 1.584662e-02
## M21                   0.79176126            0.940416477 1.223506e-03
##              PC2 Song Bird DE ASD Prenatal1 ASD DE Downreg ASD DE Upreg
## M1  2.637668e-02 0.0686560913  1.398542e-01     0.98232330 1.145216e-08
## M2  3.328735e-06 0.7890537721  9.982193e-01     0.04977199 8.118114e-01
## M3  1.000000e+00 0.6994249314  2.350972e-01     0.56240419 9.980045e-01
## M4  2.305515e-15 0.6794663082  1.000000e+00     0.01149144 9.987997e-01
## M5  7.288405e-02 0.0202334860  9.999946e-01     0.16902285 9.612071e-01
## M6  9.862370e-01 0.9070402562  9.999999e-01     0.84029789 5.008939e-01
## M7  5.518348e-08 0.0538699892  1.000000e+00     0.01095065 9.917697e-01
## M8  2.213740e-01 0.2146392324  9.999971e-01     0.81780990 4.623392e-02
## M9  9.959586e-01 0.9828514517  9.997310e-01     0.99871903 3.569456e-23
## M10 3.401034e-09 0.0259093142  1.670203e-56     0.50999623 7.432790e-01
## M11 7.292545e-04 0.7292921559  9.330775e-01     0.40700054 9.773110e-01
## M12 7.594940e-01 0.9195037035  9.965574e-01     0.98643873 9.985442e-01
## M13 2.955952e-03 0.0079243992  2.272932e-09     0.17627071 2.530046e-01
## M14 1.050465e-06 0.0000112374  1.654781e-35     0.92710459 4.966855e-03
## M15 1.392085e-01 0.2434298084  3.937756e-08     0.06829568 4.362249e-01
## M16 5.363861e-01 0.6244182204  5.820073e-01     0.30839728 1.631384e-01
## M17 9.966840e-01 0.3028552337  9.354021e-01     0.24921897 6.417563e-01
## M18 3.294613e-02 0.9725057175  9.706677e-01     0.50042332 2.184503e-02
## M19 7.270054e-01 0.2776660490  9.908645e-01     0.55088177 2.954856e-01
## M20 1.189058e-03 0.0946815450  6.286830e-02     0.04474792 6.322903e-01
## M21 1.792612e-05 0.0034648597  1.186674e-03     0.01385257 2.358044e-01
##     ASD CTX Downreg ASD CTX Upreg ASD 102 dnPTVs    SFARI ASD FMRP Targets1
## M1     7.494915e-01  2.703829e-14    0.279122496 1.651599e-01  7.881637e-03
## M2     5.223048e-01  9.970632e-01    0.948230431 9.989496e-01  9.999985e-01
## M3     9.528273e-01  9.999843e-01    0.922337645 7.227227e-01  8.378774e-01
## M4     1.219902e-02  9.999268e-01    0.886216427 9.991411e-01  9.999965e-01
## M5     7.010504e-01  5.242958e-01    0.871284409 9.728649e-01  9.996640e-01
## M6     9.716902e-01  8.880005e-01    1.000000000 5.781938e-01  1.000000e+00
## M7     1.327226e-01  9.999018e-01    1.000000000 9.976541e-01  9.999966e-01
## M8     5.328847e-01  4.844016e-04    0.783969294 8.189307e-01  7.328757e-01
## M9     9.799242e-01  4.198647e-15    0.767273854 9.865858e-01  9.996203e-01
## M10    1.689401e-07  5.565337e-01    0.014378011 4.949348e-06  2.421287e-28
## M11    3.513307e-01  9.969872e-01    1.000000000 9.912119e-01  2.089060e-01
## M12    9.992646e-01  9.964836e-01    1.000000000 9.712608e-01  9.947823e-01
## M13    4.437961e-02  9.469345e-01    1.000000000 6.713513e-01  1.727605e-02
## M14    6.063645e-01  6.029478e-01    0.001081301 6.192454e-11  2.181783e-16
## M15    1.628549e-01  5.093376e-01    0.004620462 3.983006e-03  1.389209e-01
## M16    6.376186e-01  9.642949e-02    0.282855232 2.793186e-01  6.020409e-01
## M17    5.673962e-01  1.736198e-01    1.000000000 3.334170e-01  6.861658e-01
## M18    9.076579e-01  3.414855e-04    0.014068800 9.898798e-02  1.163827e-01
## M19    5.333978e-01  2.699597e-03    1.000000000 5.866381e-01  6.721075e-01
## M20    9.789871e-02  6.244737e-01    1.000000000 8.770810e-01  8.362937e-01
## M21    4.701197e-01  8.699811e-01    1.000000000 4.861942e-02  8.153461e-01
##     FMRP Targets2 CHD8 Targets1 CHD8 Targets2       SCZ DE       BD DE
## M1   4.095473e-02  3.167298e-02  9.999192e-01 2.857653e-10 0.054090368
## M2   9.712568e-01  1.588174e-01  2.804390e-08 5.794778e-01 0.004696712
## M3   1.947233e-01  9.983422e-01  9.999934e-01 9.999636e-01 0.980852330
## M4   9.982526e-01  7.557991e-01  1.793970e-14 9.850103e-01 0.974311013
## M5   8.419424e-01  4.175197e-04  5.013581e-11 7.929966e-01 0.995751021
## M6   2.487979e-01  9.894425e-01  4.013641e-04 6.941007e-01 0.929777629
## M7   9.650118e-01  5.934635e-02  2.966515e-28 9.885675e-01 0.982596922
## M8   3.300160e-02  9.960772e-01  1.000000e+00 8.892040e-02 0.297350652
## M9   7.929112e-01  9.940158e-01  9.999822e-01 1.835371e-06 0.002577891
## M10  1.256270e-01  1.708656e-12  5.246682e-07 8.484042e-03 0.921917747
## M11  5.340016e-01  6.168471e-04  3.518266e-05 6.169365e-01 0.146593318
## M12  5.214237e-01  2.371117e-01  1.940369e-02 9.971954e-01 0.299472698
## M13  7.284996e-03  3.915347e-05  2.611235e-09 1.236247e-03 0.284908585
## M14  2.960261e-07  1.254505e-25  9.122386e-15 3.907742e-01 0.932040081
## M15  2.097548e-01  3.316486e-05  1.872106e-07 7.965069e-01 0.702988219
## M16  5.918653e-01  9.760474e-01  9.999999e-01 1.295699e-02 0.529627619
## M17  7.826138e-01  9.985623e-01  1.000000e+00 4.736431e-02 0.019467736
## M18  2.860690e-01  9.867522e-01  9.999765e-01 2.687023e-04 0.261374913
## M19  6.861128e-01  9.995542e-01  1.000000e+00 1.237460e-02 0.041972988
## M20  2.929117e-01  4.310762e-03  3.801379e-05 3.521917e-02 0.916401245
## M21  5.439622e-01  2.373493e-06  2.871068e-11 3.120775e-01 0.431704507
##     ASD Excitatory ASD Inhibitory ASD Microglia ASD Oligodendrocyte
## M1      0.97342895     0.90715505    0.01297764          0.80837359
## M2      0.16159166     0.11967822    0.64236463          0.40076730
## M3      0.90367784     0.79252380    1.00000000          1.00000000
## M4      0.84712088     0.71364679    0.47674531          1.00000000
## M5      1.00000000     0.41599342    1.00000000          1.00000000
## M6      1.00000000     1.00000000    1.00000000          1.00000000
## M7      0.75798712     0.87289162    1.00000000          1.00000000
## M8      0.20685253     0.52664401    0.68125996          1.00000000
## M9      0.89545422     0.81582510    0.66305435          1.00000000
## M10     0.89459008     0.23228663    0.29076669          1.00000000
## M11     0.60675607     0.78646887    0.62944014          1.00000000
## M12     1.00000000     0.78114538    0.25179783          0.20263332
## M13     1.00000000     0.74633570    0.58604654          1.00000000
## M14     0.83840382     0.74477220    0.01106741          1.00000000
## M15     0.50310159     0.03755666    1.00000000          1.00000000
## M16     0.22182748     0.70786062    1.00000000          1.00000000
## M17     0.45058891     0.31599313    1.00000000          0.01211158
## M18     0.05637159     0.02299887    0.03223266          1.00000000
## M19     0.71813169     1.00000000    0.12276259          0.13186173
## M20     0.63707996     0.53205664    0.38632203          1.00000000
## M21     1.00000000     0.51756259    0.37416693          0.10294288
##     ASD Astrocyte ASD Endothelial Ventricular Radial Glia Outer Radial Glia
## M1     0.78871421     0.001420584             0.520064384      0.2085175030
## M2     1.00000000     1.000000000             0.014010556      0.9374048359
## M3     0.68549724     0.734757022             0.943554408      0.9883664650
## M4     1.00000000     1.000000000             0.929038462      0.8522166400
## M5     1.00000000     0.655177645             0.214668538      0.1046203022
## M6     1.00000000     0.602716198             0.002976379      0.0001467560
## M7     1.00000000     1.000000000             0.031093841      0.0009292945
## M8     1.00000000     0.043549545             0.156756094      0.0116410895
## M9     1.00000000     0.171941375             0.067448722      0.0631452064
## M10    0.48188344     0.170978020             0.334920703      0.1847170674
## M11    0.02137618     1.000000000             0.984365117      0.9403959600
## M12    1.00000000     0.145375721             0.380592703      0.3038835117
## M13    1.00000000     1.000000000             0.622935454      0.7899601492
## M14    0.09744577     0.457265839             0.783419835      0.3310714556
## M15    0.39150006     0.434424149             0.378503579      0.5739678927
## M16    0.08174720     1.000000000             0.206345051      0.8450874205
## M17    0.36167421     1.000000000             0.164520284      0.1024180275
## M18    0.06631134     0.385896486             0.421919039      0.0160476649
## M19    1.00000000     1.000000000             0.033009206      0.0060767063
## M20    1.00000000     1.000000000             0.002983325      0.0036155318
## M21    0.24748342     1.000000000             0.546360378      0.4658343846
##     Cycling Progenitors S phase Cycling Progenitors G2M phase
## M1                 1.000000e+00                  9.772206e-01
## M2                 1.187390e-02                  9.880223e-01
## M3                 4.708982e-01                  9.836252e-01
## M4                 3.289352e-03                  3.405268e-01
## M5                 5.847467e-01                  3.865154e-01
## M6                 8.273253e-68                  4.750545e-72
## M7                 1.966441e-10                  7.944584e-09
## M8                 9.957477e-01                  9.377736e-01
## M9                 9.785584e-01                  8.303862e-01
## M10                2.669897e-01                  6.978537e-01
## M11                9.975767e-01                  9.985047e-01
## M12                5.627705e-02                  9.883687e-02
## M13                5.709906e-02                  2.072903e-01
## M14                9.758054e-01                  9.782005e-01
## M15                6.598549e-01                  7.751598e-01
## M16                9.893811e-01                  9.943979e-01
## M17                8.571790e-01                  7.042336e-01
## M18                9.796674e-01                  8.321904e-01
## M19                3.793925e-01                  7.560663e-01
## M20                2.093532e-01                  2.071115e-01
## M21                1.459046e-02                  3.194743e-02
##     Intermediate Progenitors Migrating Excitatory Maturing Excitatory
## M1              9.676626e-01         0.5588953354         0.310484934
## M2              1.465173e-10         0.8608521663         0.001772467
## M3              1.747469e-01         0.8176966869         1.000000000
## M4              9.051170e-01         0.7648880499         0.797612181
## M5              1.322429e-01         0.3907990310         0.764524122
## M6              6.394335e-01         1.0000000000         0.455802946
## M7              4.542769e-03         0.3265913294         0.675845183
## M8              8.942081e-01         1.0000000000         0.079366900
## M9              1.000000e+00         1.0000000000         0.944106994
## M10             1.496511e-01         0.0703896646         0.540931734
## M11             9.642202e-01         1.0000000000         1.000000000
## M12             4.043874e-01         0.5819084853         0.924994474
## M13             1.000000e+00         0.5449445450         0.674960515
## M14             7.903194e-01         1.0000000000         0.198377578
## M15             1.000000e+00         0.5185420259         0.005802425
## M16             9.296479e-01         0.0006507171         0.017912669
## M17             2.302212e-01         0.4834205143         0.013305891
## M18             6.776376e-01         0.4649302383         0.112429252
## M19             5.250104e-02         0.4199062645         0.477254489
## M20             1.211356e-03         1.0000000000         0.367870723
## M21             2.039745e-01         1.0000000000         0.711375333
##     Maturing Excitatory Upper Enriched Excitatory Deep Layer 1
## M1                        1.593766e-01             0.136919768
## M2                        2.968351e-01             0.258998195
## M3                        1.000000e+00             0.664508587
## M4                        9.828621e-01             0.999829213
## M5                        3.245527e-01             0.405694618
## M6                        8.424489e-01             0.827366080
## M7                        1.000000e+00             0.827366080
## M8                        5.391903e-01             0.147542266
## M9                        9.346264e-01             0.997028776
## M10                       1.568752e-05             0.004817954
## M11                       1.000000e+00             1.000000000
## M12                       9.136626e-01             0.994621762
## M13                       1.000000e+00             0.991064466
## M14                       6.724341e-02             0.042581955
## M15                       5.301986e-02             0.001330026
## M16                       1.335791e-01             0.024198991
## M17                       1.031726e-02             0.001877423
## M18                       5.206959e-01             0.716824234
## M19                       1.000000e+00             0.626511453
## M20                       3.346473e-02             0.044559292
## M21                       3.250538e-01             0.037712309
##     Excitatory Deep Layer 2 Interneuron MGE Interneuron CGE
## M1             0.2645068248    0.6458370261     0.508063057
## M2             0.6586995736    0.7414277730     0.526911472
## M3             0.8862674005    0.8480033325     0.843952263
## M4             0.3969054518    0.9433802876     0.773014557
## M5             0.3176993121    0.4999762206     0.493200857
## M6             0.8243958366    0.4085657803     0.671222783
## M7             0.0008423092    0.9044610324     0.671222783
## M8             0.0695005440    0.8679257434     1.000000000
## M9             0.9340704909    0.8542764369     1.000000000
## M10            0.0887014775    0.0006173896     0.011283632
## M11            0.8965720931    1.0000000000     1.000000000
## M12            0.5091596650    0.8226521550     1.000000000
## M13            1.0000000000    1.0000000000     0.453625316
## M14            0.2599209935    0.4565426981     0.785373313
## M15            0.0022198616    0.0556965528     0.761896171
## M16            0.0103478520    0.0004772218     0.399887148
## M17            0.0699212461    0.0019098581     0.001813483
## M18            0.4810479813    0.3483938531     0.122324849
## M19            0.9566361952    1.0000000000     1.000000000
## M20            0.0937054228    0.2117077322     0.053369319
## M21            0.7233754722    0.5638595436     0.560175925
##     Oligodendrocyte Precursor Cells  Endothelial     Pericyte    Microglia
## M1                     2.968858e-01 1.828622e-10 1.487768e-04 4.428662e-34
## M2                     4.369907e-01 9.671023e-01 4.149281e-02 9.457741e-01
## M3                     9.968134e-01 9.986846e-01 9.965668e-01 9.846914e-01
## M4                     5.008481e-01 9.824204e-01 4.290634e-05 9.994338e-01
## M5                     5.634468e-01 5.855947e-01 1.042687e-01 9.348431e-01
## M6                     4.925106e-06 9.325091e-01 9.394721e-01 9.855365e-01
## M7                     5.557036e-02 9.995432e-01 1.708225e-02 9.979568e-01
## M8                     3.766190e-01 3.697211e-04 2.539775e-06 6.455009e-02
## M9                     6.370287e-01 6.756624e-05 3.030586e-04 2.518760e-06
## M10                    6.188938e-02 6.265407e-02 9.667845e-01 4.200887e-02
## M11                    9.976890e-01 9.994888e-01 9.992866e-01 7.016842e-01
## M12                    9.348993e-01 9.782941e-01 8.741746e-01 5.621961e-01
## M13                    7.786223e-01 8.989475e-01 8.821227e-01 9.753843e-01
## M14                    8.569232e-04 3.333974e-01 6.776287e-01 2.131041e-08
## M15                    9.591354e-01 4.373000e-02 3.348670e-01 8.697679e-02
## M16                    4.942732e-02 3.556386e-02 3.740682e-05 4.187163e-01
## M17                    4.582620e-01 1.900954e-01 3.401420e-01 7.477263e-01
## M18                    2.572225e-02 3.783806e-02 4.283035e-04 7.663365e-11
## M19                    3.050425e-01 3.992549e-02 2.304611e-02 5.523216e-01
## M20                    5.661117e-01 3.030944e-01 3.275286e-01 8.167294e-01
## M21                    6.376218e-02 8.701598e-01 7.912346e-01 6.284497e-01
# FDR
FDRmat
##     Human-Specific Prenatal Human-Specific Early Postnatal Human-Specific Adult
## M1               0.95208644                    0.962001032           0.98874447
## M2               0.45751040                    0.439252543           0.07061544
## M3               0.65891364                    0.465629360           0.99952591
## M4               0.03369266                    0.557084783           0.01140606
## M5               0.99984844                    0.999972395           0.99952591
## M6               0.05254891                    0.008754709           0.49506167
## M7               0.29702206                    0.597535917           0.14429571
## M8               0.61461609                    0.561536285           0.99952591
## M9               0.51436977                    0.999972395           0.10708177
## M10              0.99984844                    0.999972395           0.87044452
## M11              0.45751040                    0.561536285           0.12957536
## M12              0.99984844                    0.999972395           0.99952591
## M13              0.01182605                    0.267045169           0.10708177
## M14              0.99984844                    0.999972395           0.99952591
## M15              0.99984844                    0.999972395           0.99952591
## M16              0.99984844                    0.999972395           0.99952591
## M17              0.65891364                    0.561536285           0.54323980
## M18              0.29702206                    0.081916077           0.12957536
## M19              0.61461609                    0.679299790           0.49506167
## M20              0.45751040                    0.267045169           0.49506167
## M21              0.32888175                    0.999972395           0.16021497
##     Human-Accelerated Genes Human-Gained Enhancers Fetal
## M1                0.9076936                    1.0000000
## M2                0.9418330                    1.0000000
## M3                0.7323725                    1.0000000
## M4                0.7323725                    0.8559998
## M5                0.4732236                    1.0000000
## M6                0.7323725                    1.0000000
## M7                0.9076936                    1.0000000
## M8                0.6422025                    1.0000000
## M9                0.9418330                    1.0000000
## M10               0.6422025                    1.0000000
## M11               0.3908048                    1.0000000
## M12               0.9418330                    1.0000000
## M13               0.6422025                    0.8559998
## M14               0.3908048                    0.8559998
## M15               0.6422025                    1.0000000
## M16               0.6422025                    1.0000000
## M17               0.7323725                    1.0000000
## M18               0.6422025                    1.0000000
## M19               0.7323725                    1.0000000
## M20               0.9076936                    1.0000000
## M21               0.9418330                    1.0000000
##     Human-Gained Enhancers Adult Human-Lossed Enhancers          PC1
## M1                     0.5316120             0.74916052 1.384927e-01
## M2                     0.9812559             0.99386701 1.762744e-06
## M3                     0.9812559             0.99386701 1.000000e+00
## M4                     0.9812559             0.74916052 1.118042e-08
## M5                     0.9812559             0.99386701 1.787709e-01
## M6                     0.9812559             0.74916052 1.000000e+00
## M7                     0.9812559             0.99386701 4.438704e-03
## M8                     0.9812559             0.05985109 1.765666e-01
## M9                     0.5316120             0.99386701 1.000000e+00
## M10                    0.5316120             0.27406654 3.626072e-07
## M11                    0.9812559             0.14093923 1.765666e-01
## M12                    0.9928329             0.99386701 1.000000e+00
## M13                    0.5316120             0.27406654 1.175465e-06
## M14                    0.6159903             0.74916052 3.626072e-07
## M15                    0.9812559             0.99386701 2.518330e-01
## M16                    0.8089048             0.30851602 2.161170e-01
## M17                    0.9812559             0.99386701 1.000000e+00
## M18                    0.9812559             0.74916052 2.088990e-01
## M19                    0.6159903             0.99386701 7.778946e-01
## M20                    0.9812559             0.99386701 4.159739e-02
## M21                    0.9812559             0.99386701 4.282271e-03
##              PC2 Song Bird DE ASD Prenatal1 ASD DE Downreg ASD DE Upreg
## M1  5.539104e-02 0.2059682739  4.195625e-01     0.99871903 1.202476e-07
## M2  1.398069e-05 0.9747134832  1.000000e+00     0.20904237 9.987997e-01
## M3  1.000000e+00 0.9571959546  6.171302e-01     0.78736587 9.987997e-01
## M4  4.841582e-14 0.9571959546  1.000000e+00     0.09696799 9.987997e-01
## M5  1.275471e-01 0.1062258014  1.000000e+00     0.46271061 9.987997e-01
## M6  1.000000e+00 0.9828514517  1.000000e+00     0.99871903 9.562520e-01
## M7  3.862844e-07 0.1885449622  1.000000e+00     0.09696799 9.987997e-01
## M8  3.320609e-01 0.5008248755  1.000000e+00     0.99871903 1.941825e-01
## M9  1.000000e+00 0.9828514517  1.000000e+00     0.99871903 7.495859e-22
## M10 3.571086e-08 0.1088191197  3.507427e-55     0.78736587 9.987997e-01
## M11 2.187763e-03 0.9571959546  1.000000e+00     0.77700104 9.987997e-01
## M12 9.381984e-01 0.9828514517  1.000000e+00     0.99871903 9.987997e-01
## M13 6.897221e-03 0.0554707944  1.591052e-08     0.46271061 6.641370e-01
## M14 5.514942e-06 0.0002359855  1.737520e-34     0.99871903 3.476798e-02
## M15 2.248753e-01 0.5112025977  2.067322e-07     0.23903489 9.160723e-01
## M16 7.509406e-01 0.9571959546  1.000000e+00     0.64763429 5.709845e-01
## M17 1.000000e+00 0.5299966590  1.000000e+00     0.58151093 9.987997e-01
## M18 6.289716e-02 0.9828514517  1.000000e+00     0.78736587 1.146864e-01
## M19 9.381984e-01 0.5299966590  1.000000e+00     0.78736587 6.894664e-01
## M20 3.121278e-03 0.2485390557  2.200391e-01     0.20904237 9.987997e-01
## M21 6.274142e-05 0.0363810271  4.984030e-03     0.09696799 6.641370e-01
##     ASD CTX Downreg ASD CTX Upreg ASD 102 dnPTVs    SFARI ASD FMRP Targets1
## M1     9.837076e-01  2.839020e-13     0.98999331 5.780598e-01  5.517146e-02
## M2     9.564279e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M3     9.992646e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M4     1.280897e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M5     9.814706e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M6     9.992646e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M7     5.574350e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M8     9.564279e-01  2.543109e-03     1.00000000 9.991411e-01  1.000000e+00
## M9     9.992646e-01  8.817158e-14     1.00000000 9.991411e-01  1.000000e+00
## M10    3.547741e-06  9.999843e-01     0.07548456 5.196816e-05  5.084702e-27
## M11    9.564279e-01  9.999843e-01     1.00000000 9.991411e-01  6.267180e-01
## M12    9.992646e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M13    3.106572e-01  9.999843e-01     1.00000000 9.991411e-01  9.069926e-02
## M14    9.564279e-01  9.999843e-01     0.02270732 1.300415e-09  2.290873e-15
## M15    5.699920e-01  9.999843e-01     0.04851485 2.788104e-02  4.862231e-01
## M16    9.564279e-01  3.375032e-01     0.98999331 8.379558e-01  1.000000e+00
## M17    9.564279e-01  5.208595e-01     1.00000000 8.752196e-01  1.000000e+00
## M18    9.992646e-01  2.390399e-03     0.07548456 4.157495e-01  4.862231e-01
## M19    9.564279e-01  1.133831e-02     1.00000000 9.991411e-01  1.000000e+00
## M20    5.139682e-01  9.999843e-01     1.00000000 9.991411e-01  1.000000e+00
## M21    9.564279e-01  9.999843e-01     1.00000000 2.552520e-01  1.000000e+00
##     FMRP Targets2 CHD8 Targets1 CHD8 Targets2       SCZ DE      BD DE
## M1   2.150123e-01  7.390363e-02  1.000000e+00 6.001072e-09 0.22717955
## M2   9.982526e-01  3.031969e-01  8.413170e-08 9.254047e-01 0.04931547
## M3   6.151146e-01  9.995542e-01  1.000000e+00 9.999636e-01 0.99575102
## M4   9.982526e-01  9.995542e-01  1.255779e-13 9.999636e-01 0.99575102
## M5   9.822661e-01  1.461319e-03  2.105704e-10 9.839203e-01 0.99575102
## M6   6.151146e-01  9.995542e-01  7.023872e-04 9.717410e-01 0.99575102
## M7   9.982526e-01  1.246273e-01  6.229682e-27 9.999636e-01 0.99575102
## M8   2.150123e-01  9.995542e-01  1.000000e+00 1.867328e-01 0.62889267
## M9   9.794786e-01  9.995542e-01  1.000000e+00 1.927139e-05 0.04931547
## M10  5.276336e-01  1.794088e-11  1.224226e-06 3.563298e-02 0.99575102
## M11  8.787081e-01  1.850541e-03  7.257177e-05 9.254047e-01 0.51307661
## M12  8.787081e-01  4.149456e-01  3.134443e-02 9.999636e-01 0.62889267
## M13  7.649245e-02  1.644446e-04  9.139324e-09 6.490296e-03 0.62889267
## M14  6.216549e-06  2.634461e-24  9.578505e-14 6.838548e-01 0.99575102
## M15  6.151146e-01  1.644446e-04  4.914278e-07 9.839203e-01 0.99575102
## M16  8.877979e-01  9.995542e-01  1.000000e+00 3.887096e-02 0.92684833
## M17  9.794786e-01  9.995542e-01  1.000000e+00 1.105167e-01 0.13627415
## M18  6.151146e-01  9.995542e-01  1.000000e+00 1.880916e-03 0.62889267
## M19  9.605579e-01  9.995542e-01  1.000000e+00 3.887096e-02 0.22035819
## M20  6.151146e-01  1.131575e-02  7.257177e-05 9.245033e-02 0.99575102
## M21  8.787081e-01  1.661445e-05  1.507311e-10 5.957843e-01 0.82416315
##     ASD Excitatory ASD Inhibitory ASD Microglia ASD Oligodendrocyte
## M1               1      1.0000000     0.1362652           1.0000000
## M2               1      0.8377476     1.0000000           1.0000000
## M3               1      1.0000000     1.0000000           1.0000000
## M4               1      1.0000000     1.0000000           1.0000000
## M5               1      1.0000000     1.0000000           1.0000000
## M6               1      1.0000000     1.0000000           1.0000000
## M7               1      1.0000000     1.0000000           1.0000000
## M8               1      1.0000000     1.0000000           1.0000000
## M9               1      1.0000000     1.0000000           1.0000000
## M10              1      1.0000000     1.0000000           1.0000000
## M11              1      1.0000000     1.0000000           1.0000000
## M12              1      1.0000000     1.0000000           1.0000000
## M13              1      1.0000000     1.0000000           1.0000000
## M14              1      1.0000000     0.1362652           1.0000000
## M15              1      0.3943449     1.0000000           1.0000000
## M16              1      1.0000000     1.0000000           1.0000000
## M17              1      1.0000000     1.0000000           0.2543432
## M18              1      0.3943449     0.2256286           1.0000000
## M19              1      1.0000000     0.6445036           0.9230321
## M20              1      1.0000000     1.0000000           1.0000000
## M21              1      1.0000000     1.0000000           0.9230321
##     ASD Astrocyte ASD Endothelial Ventricular Radial Glia Outer Radial Glia
## M1      1.0000000      0.02983226              0.71709800       0.398078869
## M2      1.0000000      1.00000000              0.09807389       0.987415758
## M3      1.0000000      1.00000000              0.98436512       0.988366465
## M4      1.0000000      1.00000000              0.98436512       0.987415758
## M5      1.0000000      1.00000000              0.45080393       0.244114038
## M6      1.0000000      1.00000000              0.03132491       0.003081876
## M7      1.0000000      1.00000000              0.13863866       0.009757592
## M8      1.0000000      0.45727022              0.43186575       0.048892576
## M9      1.0000000      0.72215378              0.23607053       0.189435619
## M10     1.0000000      0.72215378              0.61480360       0.387905842
## M11     0.4488998      1.00000000              0.98436512       0.987415758
## M12     1.0000000      0.72215378              0.61480360       0.531796145
## M13     1.0000000      1.00000000              0.76950850       0.987415758
## M14     0.5115903      1.00000000              0.91398981       0.534807736
## M15     1.0000000      1.00000000              0.61480360       0.803555050
## M16     0.5115903      1.00000000              0.45080393       0.987415758
## M17     1.0000000      1.00000000              0.43186575       0.244114038
## M18     0.5115903      1.00000000              0.63287856       0.056166827
## M19     1.0000000      1.00000000              0.13863866       0.031902708
## M20     1.0000000      1.00000000              0.03132491       0.025308722
## M21     1.0000000      1.00000000              0.71709800       0.698751577
##     Cycling Progenitors S phase Cycling Progenitors G2M phase
## M1                 1.000000e+00                  9.985047e-01
## M2                 6.127993e-02                  9.985047e-01
## M3                 8.989874e-01                  9.985047e-01
## M4                 2.302547e-02                  9.985047e-01
## M5                 1.000000e+00                  9.985047e-01
## M6                 1.737383e-66                  9.976144e-71
## M7                 2.064764e-09                  8.341813e-08
## M8                 1.000000e+00                  9.985047e-01
## M9                 1.000000e+00                  9.985047e-01
## M10                6.229761e-01                  9.985047e-01
## M11                1.000000e+00                  9.985047e-01
## M12                1.712972e-01                  5.188935e-01
## M13                1.712972e-01                  7.255159e-01
## M14                1.000000e+00                  9.985047e-01
## M15                1.000000e+00                  9.985047e-01
## M16                1.000000e+00                  9.985047e-01
## M17                1.000000e+00                  9.985047e-01
## M18                1.000000e+00                  9.985047e-01
## M19                7.967243e-01                  9.985047e-01
## M20                5.495522e-01                  7.255159e-01
## M21                6.127993e-02                  2.236320e-01
##     Intermediate Progenitors Migrating Excitatory Maturing Excitatory
## M1              1.000000e+00           1.00000000          0.81502295
## M2              3.076863e-09           1.00000000          0.03722181
## M3              5.242407e-01           1.00000000          1.00000000
## M4              1.000000e+00           1.00000000          0.98528564
## M5              5.237789e-01           1.00000000          0.98528564
## M6              1.000000e+00           1.00000000          0.91112221
## M7              3.179938e-02           1.00000000          0.98528564
## M8              1.000000e+00           1.00000000          0.33334098
## M9              1.000000e+00           1.00000000          1.00000000
## M10             5.237789e-01           0.73909148          0.94663053
## M11             1.000000e+00           1.00000000          1.00000000
## M12             8.492135e-01           1.00000000          1.00000000
## M13             1.000000e+00           1.00000000          0.98528564
## M14             1.000000e+00           1.00000000          0.59513273
## M15             1.000000e+00           1.00000000          0.06092546
## M16             1.000000e+00           0.01366506          0.09404151
## M17             5.371828e-01           1.00000000          0.09314124
## M18             1.000000e+00           1.00000000          0.39350238
## M19             2.756304e-01           1.00000000          0.91112221
## M20             1.271924e-02           1.00000000          0.85836502
## M21             5.354329e-01           1.00000000          0.98528564
##     Maturing Excitatory Upper Enriched Excitatory Deep Layer 1
## M1                        0.4781297710              0.34426529
## M2                        0.6826129514              0.54389621
## M3                        1.0000000000              1.00000000
## M4                        1.0000000000              1.00000000
## M5                        0.6826129514              0.77450791
## M6                        1.0000000000              1.00000000
## M7                        1.0000000000              1.00000000
## M8                        0.9435831108              0.34426529
## M9                        1.0000000000              1.00000000
## M10                       0.0003294379              0.03372568
## M11                       1.0000000000              1.00000000
## M12                       1.0000000000              1.00000000
## M13                       1.0000000000              1.00000000
## M14                       0.2824223225              0.13367788
## M15                       0.2783542766              0.01971294
## M16                       0.4675268880              0.12704470
## M17                       0.1083312383              0.01971294
## M18                       0.9435831108              1.00000000
## M19                       1.0000000000              1.00000000
## M20                       0.2342530915              0.13367788
## M21                       0.6826129514              0.13367788
##     Excitatory Deep Layer 2 Interneuron MGE Interneuron CGE
## M1               0.61718259     1.000000000      1.00000000
## M2               0.98804936     1.000000000      1.00000000
## M3               1.00000000     1.000000000      1.00000000
## M4               0.75772859     1.000000000      1.00000000
## M5               0.66716856     1.000000000      1.00000000
## M6               1.00000000     1.000000000      1.00000000
## M7               0.01768849     1.000000000      1.00000000
## M8               0.28111627     1.000000000      1.00000000
## M9               1.00000000     1.000000000      1.00000000
## M10              0.28111627     0.006482591      0.11847813
## M11              1.00000000     1.000000000      1.00000000
## M12              0.82248869     1.000000000      1.00000000
## M13              1.00000000     1.000000000      1.00000000
## M14              0.61718259     1.000000000      1.00000000
## M15              0.02330855     0.292406902      1.00000000
## M16              0.07243496     0.006482591      1.00000000
## M17              0.28111627     0.013369006      0.03808314
## M18              0.82248869     1.000000000      0.64220546
## M19              1.00000000     1.000000000      1.00000000
## M20              0.28111627     0.889172475      0.37358523
## M21              1.00000000     1.000000000      1.00000000
##     Oligodendrocyte Precursor Cells  Endothelial     Pericyte    Microglia
## M1                     0.7117658939 3.840107e-09 7.810782e-04 9.300190e-33
## M2                     0.7925563476 9.995432e-01 9.681655e-02 9.994338e-01
## M3                     0.9976890346 9.995432e-01 9.992866e-01 9.994338e-01
## M4                     0.7925563476 9.995432e-01 3.003444e-04 9.994338e-01
## M5                     0.7925563476 9.995432e-01 2.189643e-01 9.994338e-01
## M6                     0.0001034272 9.995432e-01 9.992866e-01 9.994338e-01
## M7                     0.1912865305 9.995432e-01 5.124674e-02 9.994338e-01
## M8                     0.7908999203 2.588048e-03 5.333527e-05 2.259253e-01
## M9                     0.8361001046 7.094455e-04 1.272846e-03 1.322349e-05
## M10                    0.1912865305 1.644669e-01 9.992866e-01 1.764373e-01
## M11                    0.9976890346 9.995432e-01 9.992866e-01 9.994338e-01
## M12                    0.9976890346 9.995432e-01 9.992866e-01 9.994338e-01
## M13                    0.9618276037 9.995432e-01 9.992866e-01 9.994338e-01
## M14                    0.0089976932 6.364860e-01 9.992866e-01 1.491729e-07
## M15                    0.9976890346 1.311900e-01 5.494601e-01 2.609304e-01
## M16                    0.1912865305 1.311900e-01 3.003444e-04 9.994338e-01
## M17                    0.7925563476 4.435559e-01 5.494601e-01 9.994338e-01
## M18                    0.1800557181 1.311900e-01 1.499062e-03 8.046533e-10
## M19                    0.7117658939 1.311900e-01 6.049603e-02 9.994338e-01
## M20                    0.7925563476 6.364860e-01 5.494601e-01 9.994338e-01
## M21                    0.1912865305 9.995432e-01 9.992866e-01 9.994338e-01

Find consensus genes

SA LV1 non-zero & Prenatal Progenitor & Prenatal PC1 (A-P) & ASD Prenatal CoExpMod

progenitor_list = unique(c(vRG,oRG,PgS,PgG2M,IP))

progen_pc1_list = progenitor_list[is.element(progenitor_list,W234_PC1)]
progen_pc1_asdprenatal_list = progen_pc1_list[is.element(progen_pc1_list,ASDPrenatal1)]

progen_pc1_asdprenatal_salv1_list = progen_pc1_asdprenatal_list[is.element(progen_pc1_asdprenatal_list,nz_genes)]
sort(progen_pc1_asdprenatal_salv1_list)
##  [1] "BAZ1B"   "BAZ2B"   "BRD8"    "CCND2"   "CHD4"    "CKAP5"   "DDX17"  
##  [8] "ILF3"    "IRF2BP2" "KIF1B"   "LMNB2"   "MCM7"    "NASP"    "PARP1"  
## [15] "PRKDC"   "SEL1L3"  "SON"     "SOX4"    "SRRM2"   "SYNE2"   "TLE1"   
## [22] "TROVE2"
# overlap with SFARI ASD genes
progen_pc1_asdprenatal_SFARI_salv1_list = progen_pc1_asdprenatal_salv1_list[is.element(progen_pc1_asdprenatal_salv1_list,SFARIASD)]
sort(progen_pc1_asdprenatal_SFARI_salv1_list)
## [1] "BAZ2B" "PRKDC" "SON"

SA LV1 non-zero & Human-specific & Prenatal Progenitor & Prenatal PC1 (A-P) & ASD Prenatal CoExpMod

hs_list = unique(c(HumanSpecific_Prenatal_Zhu,
                        HumanSpecific_EarlyPostnatal_Zhu,
                        HumanSpecific_Adult_Zhu))
progenitor_list = unique(c(vRG,oRG,PgS,PgG2M,IP))

hs_progen_list = hs_list[is.element(hs_list,progenitor_list)]
hs_progen_pc1_list = hs_progen_list[is.element(hs_progen_list,W234_PC1)]
hs_progen_pc1_asdprenatal_list = hs_progen_pc1_list[is.element(hs_progen_pc1_list,ASDPrenatal1)]
# hs_progen_pc1_asdprenatal_vocal_list = hs_progen_pc1_asdprenatal_list[is.element(hs_progen_pc1_asdprenatal_list,SongBirdDE)]

hs_progen_pc1_asdprenatal_salv1_list = hs_progen_pc1_asdprenatal_list[is.element(hs_progen_pc1_asdprenatal_list,nz_genes)]
sort(hs_progen_pc1_asdprenatal_salv1_list)
## [1] "BRD8"   "CCND2"  "DDX17"  "MCM7"   "PARP1"  "PRKDC"  "SEL1L3" "SRRM2"
# overlap with SFARI ASD genes
hs_progen_pc1_asdprenatal_SFARI_salv1_list = hs_progen_pc1_asdprenatal_salv1_list[is.element(hs_progen_pc1_asdprenatal_salv1_list,SFARIASD)]
sort(hs_progen_pc1_asdprenatal_SFARI_salv1_list)
## [1] "PRKDC"

SA LV1 non-zero & Human-specific & Vocal Learning

hs_list = unique(c(HumanSpecific_Prenatal_Zhu,
                        HumanSpecific_EarlyPostnatal_Zhu,
                        HumanSpecific_Adult_Zhu))

hs_vocal_list = hs_list[is.element(hs_list,SongBirdDE)]

hs_vocal_salv1_list = hs_vocal_list[is.element(hs_vocal_list,nz_genes)]
sort(hs_vocal_salv1_list)
##  [1] "ACOT7"   "AKR1B1"  "ANP32B"  "AP3M2"   "ARGLU1"  "ATIC"    "BACH1"  
##  [8] "BRI3"    "BRWD3"   "BTAF1"   "CEP63"   "CHD9"    "CHUK"    "CORO1C" 
## [15] "CYB5A"   "DDX18"   "DMXL2"   "DPP7"    "DUSP5"   "EIF3I"   "FAR1"   
## [22] "FBXO21"  "FCHSD2"  "FEM1C"   "GNL3"    "GSPT1"   "H3F3A"   "HARS"   
## [29] "HEATR1"  "HEBP2"   "HSPE1"   "IQGAP1"  "JARID2"  "KCTD21"  "KLHDC4" 
## [36] "MAP3K3"  "MAPK14"  "MED12"   "MPV17"   "MRPS6"   "NAB1"    "NCOA2"  
## [43] "NDUFS5"  "NIT2"    "NOL6"    "NSMAF"   "OGT"     "PARD6A"  "POLD3"  
## [50] "POLR2D"  "PRKRIP1" "PSME4"   "PSMF1"   "RAD51C"  "RAD54L"  "RALGAPB"
## [57] "RNF126"  "RNF19B"  "RRP15"   "SAAL1"   "SETMAR"  "SLC7A6"  "SPG7"   
## [64] "SSB"     "STIL"    "STRA13"  "STRAP"   "TAGLN2"  "TDG"     "TET2"   
## [71] "TMEM5"   "TOMM7"   "UCP2"    "VPS8"    "WDR7"    "WDYHV1"  "XBP1"   
## [78] "YARS"
# overlap with SFARI ASD genes
hs_vocal_SFARI_salv1_list = hs_vocal_salv1_list[is.element(hs_vocal_salv1_list,SFARIASD)]
sort(hs_vocal_SFARI_salv1_list)
## [1] "BRWD3"   "BTAF1"   "DMXL2"   "JARID2"  "RALGAPB" "TET2"